From c51ae395ce75b92867f8f6c3abbdd050b71d5e68 Mon Sep 17 00:00:00 2001 From: Freddie Witherden Date: Fri, 15 Aug 2008 10:28:48 +0000 Subject: [PATCH] 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 --- lib/betawidget/hBox.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/betawidget/hBox.c b/lib/betawidget/hBox.c index cd570efa0..1c364611e 100644 --- a/lib/betawidget/hBox.c +++ b/lib/betawidget/hBox.c @@ -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++;