From edf856006d34c72feed2ea11dde631957976530e Mon Sep 17 00:00:00 2001 From: giraffedata Date: Thu, 20 May 2010 23:22:44 +0000 Subject: fix memory leak git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1218 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- other/pamarith.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'other') diff --git a/other/pamarith.c b/other/pamarith.c index 7d973222..d8ea19fa 100644 --- a/other/pamarith.c +++ b/other/pamarith.c @@ -400,10 +400,15 @@ doNormalizedArith(struct pam * const inpam1P, struct pam * const outpamP, enum function const function) { + unsigned int const operandCt = 2; + tuplen * tuplerown1; tuplen * tuplerown2; tuplen * tuplerownOut; unsigned int row; + samplen * operands; + + MALLOCARRAY_NOFAIL(operands, operandCt); tuplerown1 = pnm_allocpamrown(inpam1P); tuplerown2 = pnm_allocpamrown(inpam2P); @@ -418,14 +423,9 @@ doNormalizedArith(struct pam * const inpam1P, unsigned int outplane; for (outplane = 0; outplane < outpamP->depth; ++outplane) { - unsigned int const operandCt = 2; unsigned int const plane1 = MIN(outplane, inpam1P->depth-1); unsigned int const plane2 = MIN(outplane, inpam2P->depth-1); - samplen * operands; - - MALLOCARRAY_NOFAIL(operands, operandCt); - operands[0] = tuplerown1[col][plane1]; operands[1] = tuplerown2[col][plane2]; @@ -442,6 +442,7 @@ doNormalizedArith(struct pam * const inpam1P, pnm_freepamrown(tuplerown1); pnm_freepamrown(tuplerown2); pnm_freepamrown(tuplerownOut); + free(operands); } @@ -700,18 +701,22 @@ doUnNormalizedArith(struct pam * const inpam1P, maxval to do the computation without time-consuming normalization of sample values. -----------------------------------------------------------------------------*/ + unsigned int const operandCt = 2; sample const maxval = outpamP->maxval; tuple * tuplerow1; tuple * tuplerow2; tuple * tuplerowOut; unsigned int row; + sample * operands; /* Input conditions: */ assert(inpam1P->maxval == maxval); assert(inpam2P->maxval == maxval); assert(outpamP->maxval == maxval); + MALLOCARRAY_NOFAIL(operands, operandCt); + tuplerow1 = pnm_allocpamrow(inpam1P); tuplerow2 = pnm_allocpamrow(inpam2P); tuplerowOut = pnm_allocpamrow(outpamP); @@ -725,14 +730,9 @@ doUnNormalizedArith(struct pam * const inpam1P, unsigned int outplane; for (outplane = 0; outplane < outpamP->depth; ++outplane) { - unsigned int const operandCt = 2; unsigned int const plane1 = MIN(outplane, inpam1P->depth-1); unsigned int const plane2 = MIN(outplane, inpam2P->depth-1); - sample * operands; - - MALLOCARRAY_NOFAIL(operands, operandCt); - operands[0] = tuplerow1[col][plane1]; operands[1] = tuplerow2[col][plane2]; @@ -750,6 +750,8 @@ doUnNormalizedArith(struct pam * const inpam1P, pnm_freepamrow(tuplerow1); pnm_freepamrow(tuplerow2); pnm_freepamrow(tuplerowOut); + + free(operands); } -- cgit 1.4.1