diff options
Diffstat (limited to 'fslsfonts.c')
-rw-r--r-- | fslsfonts.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/fslsfonts.c b/fslsfonts.c index 3138a81..3608e5a 100644 --- a/fslsfonts.c +++ b/fslsfonts.c @@ -264,17 +264,19 @@ get_list(const char *pattern) program_name, pattern); return; } - if (font_list) - font_list = realloc(font_list, (font_cnt + (unsigned) available) - * sizeof(FontList)); - else - font_list = malloc((font_cnt + (unsigned) available) - * sizeof(FontList)); - if (font_list == NULL) { - fprintf(stderr, "%s: unable to allocate %zu bytes for font list\n", - program_name, - (font_cnt + (unsigned) available) * sizeof(FontList)); - exit(-1); + else { + FontList *old_list = font_list; + + font_list = realloc(old_list, (font_cnt + (unsigned) available) + * sizeof(FontList)); + + if (font_list == NULL) { + free(old_list); + fprintf(stderr, "%s: unable to allocate %zu bytes for font list\n", + program_name, + (font_cnt + (unsigned) available) * sizeof(FontList)); + exit(-1); + } } for (i = 0; i < available; i++) { font_list[font_cnt].name = fonts[i]; |