[tex-live] shell_escape extension patch

Jonathan Kew jonathan_kew at sil.org
Sat Jun 17 12:48:43 CEST 2006


On 17 Jun 2006, at 11:24 am, Akira Kakuto wrote:

> Hi Jonathan,
>
>> Sorry if I'm being slow this morning, but in looking at this code,
>> I'm puzzled why there's a need to set (and then free)
>> fullnameoffile .... I don't see what it's used for.
>
> When makefullnamestring()
>
> strnumber
> makefullnamestring()
> {
>   return maketexstring(fullnameoffile);
> }
>
> is called, assertion fails in maketexstring if
> fullnameoffile == NULL, whereas maketexstring in
> pdftex allows NULL.

But as I read it, your suggested change frees fullnameoffile again,  
before open_in_or_pipe returns. So by the time makefullnamestring()  
would be called, that memory is gone. If you get the right result,  
it's only by chance, because the memory hasn't been re-used yet, but  
the behavior is undefined, and sooner or later it'll fail for someone.

(To confirm this, you could reset fullnameoffile to NULL after the  
free() call, as the memory it pointed to is no longer allocated; then  
I expect the maketexstring assertion will fail again.)

In the non-pdftex case, rather than freeing fullnameoffile right  
after opening the pipe, you can free it right before allocating a new  
one:

        fname = (string)xmalloc(strlen(nameoffile+1));
        strcpy(fname,nameoffile+1);
+#if !defined(pdfTeX) && !defined(pdfeTeX)
+      if (fullnameoffile) free(fullnameoffile);
+      fullnameoffile = xstrdup(fname);
+#endif
        *f_ptr = popen(fname+1,"r");
        free(fname);

That way, the new value stays around long enough to be useful.

Or am I misunderstanding how this all fits together?

JK



More information about the tex-live mailing list