# HG changeset patch # User Matti Hamalainen # Date 1583769546 -7200 # Node ID ea6bcbfb9d183873a868c877dfdb05fb68de7184 # Parent 49c818acbbbef276104417f5b70ea5c8e4be76f7 Comments and cleanup. diff -r 49c818acbbbe -r ea6bcbfb9d18 th_ioctx_mem.c --- a/th_ioctx_mem.c Mon Mar 09 16:22:01 2020 +0200 +++ b/th_ioctx_mem.c Mon Mar 09 17:59:06 2020 +0200 @@ -12,15 +12,18 @@ { size_t grow; + // Check against max size if (ctx->maxSize > 0 && newSize > ctx->maxSize) { ctx->status = THERR_BOUNDS; return FALSE; } + // New size is smaller than old if (newSize < ctx->memAlloc) - return TRUE; + goto out; + // Compute the allocation grow amount grow = (ctx->minAlloc > 0) ? ctx->minAlloc : 8 * 1024; if (newSize - ctx->memAlloc > grow) grow += newSize - ctx->memAlloc; @@ -31,6 +34,7 @@ return FALSE; } + // Grow the buffer ctx->memAlloc += grow; if ((ctx->memData = th_realloc(ctx->memData, ctx->memAlloc)) == NULL) { @@ -38,6 +42,7 @@ return FALSE; } +out: ctx->memSize = newSize; return TRUE;