On Fri, Jan 16, 2026 at 06:03:04PM +0200, Eli Zaretskii wrote:
> In addition, the !PIPE_USE_FORK branch of get_output_from_program had
> a few problems: it failed to use the FILENAME argument when
> constructing the command line for popen, used the null
> formatter_args[2] in sprintf, and had a few other minor issues.
> 
> Here's the patch to fix all that, after which all Info tests pass.  I
> will see about writing a Windows batch file that works like
> info/info-hooks-default/manual-not-found, so that "make install" could
> install it.

I've committed this, except for moving one line: "free (cmdline);".
This moved the 'free' after a possible return statement ("return 127;"),
which would be a memory leak if that return statement were run.

Please let me know if there is a problem with running "free" on
the argument to "popen" before calling "pclose".

> --- info/run-external.c~0     2026-01-01 20:44:32.000000000 +0200
> +++ info/run-external.c       2026-01-16 17:40:33.599793200 +0200
> @@ -88,12 +88,21 @@ get_output_from_program (char *filename,
>    {
>      FILE *fpipe;
>      char *cmdline;
> -    size_t cmdlen = 0;
>      int save_stderr = dup (fileno (stderr));
>      int fd_err = open (NULL_DEVICE, O_WRONLY, 0666);
> +    size_t cmdlen = strlen (filename);
>      int i;
>  
> -    for (i = 0; formatter_args[i]; i++)
> +#ifdef __MINGW32__
> +    /* Mirror all forward slashes in FILENAME to backslashes, since
> +       otherwise the Windows shell might fail to run the script.  */
> +    filename = xstrdup (filename);
> +    for (i = 0; i < cmdlen; i++)
> +      if (filename[i] == '/')
> +     filename[i] = '\\';
> +#endif
> +
> +    for (i = 1; formatter_args[i]; i++)
>        cmdlen += strlen (formatter_args[i]);
>      /* Add-ons: 2 blanks, 2 quotes for the formatter program, 1
>         terminating null character.  */
> @@ -102,10 +111,12 @@ get_output_from_program (char *filename,
>  
>      if (fd_err > 2)
>        dup2 (fd_err, fileno (stderr)); /* Don't print errors. */
> -    sprintf (cmdline, "\"%s\" %s %s",
> -             formatter_args[0], formatter_args[1], formatter_args[2]);
> +    sprintf (cmdline, "\"%s\" %s %s", filename,
> +          formatter_args[1], formatter_args[2] ? formatter_args[2] : "");
> +#ifdef __MINGW32__
> +    free (filename);
> +#endif
>      fpipe = popen (cmdline, "r");
> -    free (cmdline);
>      if (fd_err > 2)
>        close (fd_err);
>      dup2 (save_stderr, fileno (stderr));
> @@ -113,6 +124,7 @@ get_output_from_program (char *filename,
>        return 127;
>      output = read_from_fd (fileno (fpipe));
>      int pclose_status = pclose (fpipe);
> +    free (cmdline);
>      if (pclose_status != -1)
>        exit_status = pclose_status;
>      else
> --- /dev/null 1970-01-01 02:00:00.000000000 +0200
> +++ info/t/config/texinfo/info-hooks/manual-not-found.cmd     2026-01-16 
> 17:34:37.235683500 +0200
> @@ -0,0 +1,2 @@
> +@echo off
> +exit 1

Reply via email to