+2024-10-06 Bruno Haible <bruno@clisp.org>
+
+ javacomp, javaversion: Fix resource leak.
+ * lib/javacomp.c (execute_and_read_line): When fdopen fails, terminate
+ the program.
+ * lib/javaversion.c (execute_and_read_line): Likewise. When we can't
+ read a single line, call fclose and wait_subprocess, to free resources.
+
2024-10-04 Bruno Haible <bruno@clisp.org>
iconv_open: Fix undefined behaviour.
/* Retrieve its result. */
fp = fdopen (fd[0], "r");
if (fp == NULL)
- {
- error (0, errno, _("fdopen() failed"));
- return NULL;
- }
+ error (EXIT_FAILURE, errno, _("fdopen() failed"));
line = NULL; linesize = 0;
linelen = getline (&line, &linesize, fp);
char *line;
size_t linesize;
size_t linelen;
- int exitstatus;
/* Open a pipe to the JVM. */
child = create_pipe_in (progname, prog_path, prog_argv, NULL,
/* Retrieve its result. */
fp = fdopen (fd[0], "r");
if (fp == NULL)
- {
- error (0, errno, _("fdopen() failed"));
- return false;
- }
+ error (EXIT_FAILURE, errno, _("fdopen() failed"));
line = NULL; linesize = 0;
linelen = getline (&line, &linesize, fp);
if (linelen == (size_t)(-1))
{
error (0, 0, _("%s subprocess I/O error"), progname);
- return false;
+ fclose (fp);
+ wait_subprocess (child, progname, true, false, true, false, NULL);
}
- if (linelen > 0 && line[linelen - 1] == '\n')
- line[linelen - 1] = '\0';
+ else
+ {
+ int exitstatus;
- fclose (fp);
+ if (linelen > 0 && line[linelen - 1] == '\n')
+ line[linelen - 1] = '\0';
- /* 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 false;
- }
+ fclose (fp);
- l->line = line;
+ /* Remove zombie process from process list, and retrieve exit status. */
+ exitstatus =
+ wait_subprocess (child, progname, true, false, true, false, NULL);
+ if (exitstatus == 0)
+ {
+ l->line = line;
+ return false;
+ }
+ }
+ free (line);
return false;
}