Fix bad call to fclose with NULL pointer

This commit is contained in:
mayeut 2016-04-30 01:50:33 +02:00
parent be42e72d22
commit f40a2ff2ad
1 changed files with 38 additions and 39 deletions

View File

@ -1842,7 +1842,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split)
if(two)
{
v = *red + adjustR; ++red;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@ -1850,13 +1850,13 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(triple)
{
v = *green + adjustG; ++green;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
v = *blue + adjustB; ++blue;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@ -1913,7 +1913,6 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
destname = (char*)malloc(strlen(outfile) + 8);
if(destname == NULL){
fprintf(stderr, "imagetopnm: memory out\n");
fclose(fdest);
return 1;
}
for (compno = 0; compno < ncomp; compno++)
@ -1953,7 +1952,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
for (i = 0; i < wr * hr; i++)
{
v = *red + adjustR; ++red;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
@ -1961,7 +1960,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(has_alpha)
{
v = *alpha++;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
if(v > 65535) v = 65535; else if(v < 0) v = 0;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);