commit 04e7c9708159ba375b3f3ca868529877c8497514
parent 6f0579f5a686df156d391eca1c41a9da462d38a7
Author: Frederic Cambus <fred@statdns.com>
Date: Tue, 10 Dec 2019 10:16:54 +0100
Use strdup() when assigning fileName and fext fallback values.
This allows us to call free() unconditionally, and appease LeakSanitizer.
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/ansilove.c b/src/ansilove.c
@@ -205,7 +205,7 @@ main(int argc, char *argv[])
if (asprintf(&fileName, "%s%s", input, ".png") == -1)
errx(EXIT_FAILURE, "Memory allocation error.");
} else {
- fileName = output;
+ fileName = strdup(output);
}
/* display name of input and output files */
@@ -214,7 +214,7 @@ main(int argc, char *argv[])
/* get file extension */
char *fext = strrchr(input, '.');
- fext = fext ? strtolower(strdup(++fext)) : "";
+ fext = fext ? strtolower(strdup(++fext)) : strdup("");
/* check if current file has a .diz extension */
if (!strcmp(fext, "diz"))
@@ -273,6 +273,9 @@ main(int argc, char *argv[])
if (options.scale_factor)
fprintf(messages, "Scale factor: %d\n", options.scale_factor);
+
+ free(fileName);
+ free(fext);
}
/* either display SAUCE or tell us if there is no record */