Fix resource leaks & unchecked resource allocations

This commit is contained in:
mayeut 2015-09-25 00:08:34 +02:00
parent f9df8ba19a
commit b9ca882749
5 changed files with 14 additions and 5 deletions

View File

@ -903,6 +903,10 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
<<-- <<-- <<-- <<-- */
fdest = fopen(outfile, "wb");
if (!fdest) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
return 1;
}
w = (int)image->comps[0].w;
h = (int)image->comps[0].h;

View File

@ -486,7 +486,7 @@ fin:
}
fclose(writer);
if(fails) remove(write_idf);
if(fails) (void)remove(write_idf); /* ignore return value */
return fails;
}/* imagetopng() */

View File

@ -456,7 +456,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
strncpy(parameters->infile, infilename, sizeof(infilename));
strncpy(parameters->infile, infilename, sizeof(infilename) - 1U);
/*Set output file*/
strcpy(temp_ofname,get_file_name(image_filename));
@ -466,7 +466,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
}
if(img_fol->set_out_format==1){
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
strncpy(parameters->outfile, outfilename, sizeof(outfilename));
strncpy(parameters->outfile, outfilename, sizeof(outfilename) - 1U);
}
return 0;
}
@ -612,6 +612,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
substr2++; /* skip '@' character */
}
substr1 = (char*) malloc((len+1)*sizeof(char));
if (substr1 == NULL) {
return 1;
}
memcpy(substr1,opj_optarg,len);
substr1[len] = '\0';
if (sscanf(substr1, "%d,%d,%d,%d,%c", &width, &height, &ncomp, &bitdepth, &signo) == 5) {
@ -663,7 +666,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
}
}
if (substr1) free(substr1);
free(substr1);
if (wrong) {
fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n");

View File

@ -1550,7 +1550,7 @@ int main(int argc, char **argv)
/* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index);
if(failed) remove(parameters.outfile);
if(failed) (void)remove(parameters.outfile); /* ignore return value */
}
destroy_parameters(&parameters);
if (numDecompressedImages) {

View File

@ -134,6 +134,7 @@ static int get_num_images(char *imgdirpath){
continue;
num_images++;
}
closedir(dir);
return num_images;
}
@ -160,6 +161,7 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
}