Skip to content

Commit

Permalink
Fix Issue #6: Remove unnecessary null pointer checks
Browse files Browse the repository at this point in the history
  • Loading branch information
saitoha committed Sep 26, 2014
1 parent d8d46b7 commit 0221665
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
41 changes: 12 additions & 29 deletions converters/img2sixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ prepare_specified_palette(char const *mapfile, int reqcolors)

mappixels = load_image_file(mapfile, &map_sx, &map_sy,
&frame_count, &loop_count, &delays);
if (delays) {
free(delays);
}
free(delays);
if (!mappixels) {
return NULL;
}
Expand Down Expand Up @@ -289,9 +287,9 @@ convert_to_sixel(char const *filename, settings_t *psettings)
sixel_output_t *context = NULL;
sixel_dither_t *dither = NULL;
int sx, sy;
int frame_count;
int loop_count;
int *delays;
int frame_count = 1;
int loop_count = 1;
int *delays = NULL;
int i;
int c;
int n;
Expand All @@ -302,10 +300,6 @@ convert_to_sixel(char const *filename, settings_t *psettings)
int lag = 0;
clock_t start;

frame_count = 1;
loop_count = 1;
delays = 0;

if (psettings->reqcolors < 2) {
psettings->reqcolors = 2;
}
Expand Down Expand Up @@ -569,24 +563,15 @@ convert_to_sixel(char const *filename, settings_t *psettings)
if (dither) {
sixel_dither_unref(dither);
}
if (frames) {
free(frames);
}
if (pixels) {
free(pixels);
}
if (delays) {
free(delays);
}
if (scaled_frame) {
free(scaled_frame);
}
if (mappixels) {
free(mappixels);
}
if (context) {
sixel_output_unref(context);
}
free(frames);
free(pixels);
free(delays);
free(scaled_frame);
free(mappixels);

return nret;
}

Expand Down Expand Up @@ -767,7 +752,7 @@ main(int argc, char *argv[])

settings_t settings = {
-1, /* reqcolors */
NULL, /* *mapfile */
NULL, /* mapfile */
0, /* monochrome */
DIFFUSE_AUTO, /* method_for_diffuse */
LARGE_AUTO, /* method_for_largest */
Expand Down Expand Up @@ -1080,9 +1065,7 @@ main(int argc, char *argv[])
show_help();

end:
if (settings.mapfile) {
free(settings.mapfile);
}
free(settings.mapfile);
return exit_code;
}

Expand Down
4 changes: 1 addition & 3 deletions src/dither.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ sixel_dither_create(int ncolors)
void
sixel_dither_destroy(sixel_dither_t *dither)
{
if (dither->cachetable) {
free(dither->cachetable);
}
free(dither->cachetable);
free(dither);
}

Expand Down
6 changes: 2 additions & 4 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ sixel_create_image(unsigned char *pixels, int sx, int sy, int depth,
void
sixel_image_destroy(sixel_image_t *im)
{
if (im->dither) {
sixel_dither_unref(im->dither);
}
if (im->pixels && !im->borrowed) {
sixel_dither_unref(im->dither);
if (!im->borrowed) {
free(im->pixels);
}
free(im);
Expand Down

0 comments on commit 0221665

Please sign in to comment.