1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-05-13 15:13:36 +00:00

javacomp: Fix memory leak.

* lib/javacomp.c (execute_and_read_line): Free the line after getline()
failed.
This commit is contained in:
Bruno Haible
2025-07-29 14:29:19 +02:00
parent 21b208f43a
commit f0773a994e
2 changed files with 25 additions and 19 deletions

View File

@@ -1,3 +1,9 @@
2025-07-29 Bruno Haible <bruno@clisp.org>
javacomp: Fix memory leak.
* lib/javacomp.c (execute_and_read_line): Free the line after getline()
failed.
2025-07-29 Bruno Haible <bruno@clisp.org>
git-merge-changelog: Fix essential functionality (regr. 2023-05-21).

View File

@@ -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';
/* Read until EOF (otherwise the child process may get a SIGPIPE signal). */
while (getc (fp) != EOF)
;
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)
else
{
free (line);
return NULL;
}
int exitstatus;
return line;
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)
;
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)
return line;
}
free (line);
return NULL;
}
/* Executes a program, assumed to be a Java compiler with '-version' option.