From: James Jones Date: Fri, 6 May 2022 17:36:26 +0000 (-0500) Subject: Free result of file_name_stripped() when needed (CID #1504303) (#4494) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cac6c997f87b3035c22a7bd89830af2a86e63fc0;p=thirdparty%2Ffreeradius-server.git Free result of file_name_stripped() when needed (CID #1504303) (#4494) --- diff --git a/scripts/jlibtool.c b/scripts/jlibtool.c index 28c15cc5820..46f691440b6 100644 --- a/scripts/jlibtool.c +++ b/scripts/jlibtool.c @@ -1276,7 +1276,7 @@ static char const *file_name(char const *path) * @param path to check * @return pointer in path. */ -static char const *file_name_stripped(char const *path) +static char const *file_name_stripped(char const *path, bool *allocated) { char const *name; char const *ext; @@ -1291,9 +1291,11 @@ static char const *file_name_stripped(char const *path) strncpy(trimmed, name, ext - name); trimmed[ext-name] = 0; + *allocated = true; return trimmed; } + *allocated = false; return name; } @@ -2224,10 +2226,15 @@ static void generate_def_file(command_t *cmd) hDef = fopen(def_file, "w"); if (hDef != NULL) { - fprintf(hDef, "LIBRARY '%s' INITINSTANCE\n", file_name_stripped(cmd->output_name)); + bool stripped_allocated; + char const *stripped; + + stripped = file_name_stripped(cmd->output_name, &stripped_allocated); + fprintf(hDef, "LIBRARY '%s' INITINSTANCE\n", stripped); fprintf(hDef, "DATA NONSHARED\n"); fprintf(hDef, "EXPORTS\n"); fclose(hDef); + if (stripped_allocated) lt_const_free(stripped); #if 0 /* No num_obj_files ? */ for (a = 0; a < cmd->num_obj_files; a++) {