about summary refs log tree commit diff
path: root/other
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-05-20 23:22:44 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-05-20 23:22:44 +0000
commitedf856006d34c72feed2ea11dde631957976530e (patch)
tree7bfd04d8a522959af5e09a55e1cb00bc7c7254b6 /other
parentfc66773106fe87693c095e4b564cf0bd369c3857 (diff)
downloadnetpbm-mirror-edf856006d34c72feed2ea11dde631957976530e.tar.gz
netpbm-mirror-edf856006d34c72feed2ea11dde631957976530e.tar.xz
netpbm-mirror-edf856006d34c72feed2ea11dde631957976530e.zip
fix memory leak
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1218 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'other')
-rw-r--r--other/pamarith.c22
1 files changed, 12 insertions, 10 deletions
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);
 }