Fix a potential memory leak in hBox.c, plus some minor cleanup.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5818 4a71c877-e1ca-e34f-864e-861f7616d084
master
Freddie Witherden 2008-08-15 10:28:48 +00:00
parent d8aca5b13f
commit c51ae395ce
1 changed files with 13 additions and 9 deletions

View File

@ -102,19 +102,12 @@ bool hBoxDoLayoutImpl(widget *self)
point offset;
} sizeInfo;
int i, temp = 0;
int i, temp;
const int numChildren = vectorSize(self->children);
const size minSize = widgetGetMinSize(self);
sizeInfo *childSizeInfo = malloc(sizeof(sizeInfo) * numChildren);
bool maxedOut = false;
// First make sure we are large enough to hold all of our children
if (self->size.x < minSize.x
|| self->size.y < minSize.y)
{
return false;
}
// Make sure malloc did not return NULL
if (childSizeInfo == NULL)
{
@ -122,6 +115,16 @@ bool hBoxDoLayoutImpl(widget *self)
return false;
}
// First make sure we are large enough to hold all of our children
if (self->size.x < minSize.x
|| self->size.y < minSize.y)
{
// Release the childSizeInfo array
free(childSizeInfo);
return false;
}
// Get the min/max size of our children
for (i = 0; i < numChildren; i++)
{
@ -137,7 +140,7 @@ bool hBoxDoLayoutImpl(widget *self)
{
sizeInfo *child = &childSizeInfo[i];
// Make the child as heigh as possible
// Make the child as high as possible
child->currentSize.y = MIN(self->size.y, child->maxSize.y);
// Make the child as thin as possible, noting how much x-space is left
@ -169,6 +172,7 @@ bool hBoxDoLayoutImpl(widget *self)
{
sizeInfo *child = &childSizeInfo[i];
// If the child is not as wide as possible; widen it
if (child->currentSize.x < child->maxSize.x)
{
child->currentSize.x++;