cvs: gd /libgd/src gd_nnquant.c

From: Date: Tue, 01 Jan 2008 18:55:20 +0000
Subject: cvs: gd /libgd/src gd_nnquant.c
Groups: php.gd.cvs 
Request: Send a blank email to php-gd-cvs+get-399@lists.php.net to get a copy of this message
pajoye Tue Jan 1 18:55:20 2008 UTC Modified files: /gd/libgd/src gd_nnquant.c Log: - #58, free neuquant and temp buffer on exit http://cvs.php.net/viewvc.cgi/gd/libgd/src/gd_nnquant.c?r1=1.2&r2=1.3&diff_format=u Index: gd/libgd/src/gd_nnquant.c diff -u gd/libgd/src/gd_nnquant.c:1.2 gd/libgd/src/gd_nnquant.c:1.3 --- gd/libgd/src/gd_nnquant.c:1.2 Mon Dec 31 01:58:18 2007 +++ gd/libgd/src/gd_nnquant.c Tue Jan 1 18:55:20 2008 @@ -481,7 +481,7 @@ nn_quant *nnq = NULL; int row; - unsigned char *rgba; + unsigned char *rgba = NULL; gdImagePtr dst; /* Default it to 3 */ @@ -498,8 +498,9 @@ */ rgba = (unsigned char *) gdMalloc(gdImageSX(im) * gdImageSY(im) * 4); if (!rgba) { - return NULL; + goto done; } + d = rgba; for (row = 0; row < gdImageSY(im); row++) { int *p = im->tpixels[row]; @@ -517,7 +518,7 @@ nnq = (nn_quant *) gdMalloc(sizeof(nn_quant)); if (!nnq) { - return NULL; + goto done; } initnet(nnq, rgba, gdImageSY(im) * gdImageSX(im) * 4, sample_factor, newcolors); @@ -528,22 +529,23 @@ inxbuild(nnq); /* remapping colormap to eliminate opaque tRNS-chunk entries... */ for (top_idx = newcolors-1, bot_idx = x = 0; x < newcolors; ++x) { - if (map[x][3] == 255) /* maxval */ + if (map[x][3] == 255) { /* maxval */ remap[x] = top_idx--; - else + } else { remap[x] = bot_idx++; + } } if (bot_idx != top_idx + 1) { fprintf(stderr, " internal logic error: remapped bot_idx = %d, top_idx = %d\n", bot_idx, top_idx); fflush(stderr); - return NULL; + goto done; } dst = gdImageCreate(gdImageSX(im), gdImageSY(im)); if (!dst) { - return NULL; + goto done; } for (x = 0; x < newcolors; ++x) { @@ -571,5 +573,14 @@ ]; } } + +done: + if (rgba) { + gdFree(rgba); + } + + if (nnq) { + gdFree(nnq); + } return dst; }

« previous php.gd.cvs (#399) next »