]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
javacomp: Fix memory leak.
authorBruno Haible <bruno@clisp.org>
Tue, 29 Jul 2025 12:29:19 +0000 (14:29 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 29 Jul 2025 12:29:19 +0000 (14:29 +0200)
* lib/javacomp.c (execute_and_read_line): Free the line after getline()
failed.

ChangeLog
lib/javacomp.c

index e18ef6504860c8405a91bbe00d1fc570968a74ee..f0200c92ece1cbd4f5d5573b311c3700c03fc233 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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).
index 936cf798102a82603c73474cd479fe89e424e255..ff18f79e3528e1e0a293ffa0985f7cb44c071f0f 100644 (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';
+  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.