From: Bruno Haible Date: Tue, 29 Jul 2025 12:29:19 +0000 (+0200) Subject: javacomp: Fix memory leak. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0773a994eb75ceeeb44e39145c842044357a1ad;p=thirdparty%2Fgnulib.git javacomp: Fix memory leak. * lib/javacomp.c (execute_and_read_line): Free the line after getline() failed. --- diff --git a/ChangeLog b/ChangeLog index e18ef65048..f0200c92ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-07-29 Bruno Haible + + javacomp: Fix memory leak. + * lib/javacomp.c (execute_and_read_line): Free the line after getline() + failed. + 2025-07-29 Bruno Haible git-merge-changelog: Fix essential functionality (regr. 2023-05-21). diff --git a/lib/javacomp.c b/lib/javacomp.c index 936cf79810..ff18f79e35 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -338,7 +338,6 @@ execute_and_read_line (const char *progname, char *line; size_t linesize; size_t linelen; - int exitstatus; /* Open a pipe to the program. */ child = create_pipe_in (progname, prog_path, prog_argv, NULL, NULL, @@ -359,27 +358,28 @@ execute_and_read_line (const char *progname, error (0, 0, _("%s subprocess I/O error"), progname); fclose (fp); wait_subprocess (child, progname, true, false, true, false, NULL); - return NULL; } - if (linelen > 0 && line[linelen - 1] == '\n') - line[linelen - 1] = '\0'; + else + { + int exitstatus; + + if (linelen > 0 && line[linelen - 1] == '\n') + line[linelen - 1] = '\0'; - /* Read until EOF (otherwise the child process may get a SIGPIPE signal). */ - while (getc (fp) != EOF) - ; + /* Read until EOF (otherwise the child process may get a SIGPIPE signal). */ + while (getc (fp) != EOF) + ; - fclose (fp); + fclose (fp); - /* Remove zombie process from process list, and retrieve exit status. */ - exitstatus = - wait_subprocess (child, progname, true, false, true, false, NULL); - if (exitstatus != 0) - { - free (line); - return NULL; + /* Remove zombie process from process list, and retrieve exit status. */ + exitstatus = + wait_subprocess (child, progname, true, false, true, false, NULL); + if (exitstatus == 0) + return line; } - - return line; + free (line); + return NULL; } /* Executes a program, assumed to be a Java compiler with '-version' option.