file.c (file_read): Copy name when duplicating input file spec.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 13 May 2011 19:26:13 +0000 (20:26 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 13 May 2011 19:26:13 +0000 (20:26 +0100)
commitd105b00f8fd71a064353bc17192fc4985726721a
tree7124ca5f9b54e75de2a4f98c80b104a297e456ce
parent86c9bc4bc9e9b99482bcc5a2c6da8f5ec7516f69
file.c (file_read): Copy name when duplicating input file spec.

If only one filespec is provided to the file endpoint, then it copies
the input spec (which it's already parsed) to the output.  But this
isn't enough because the spec might contain a dynamically allocated
filename.  The function `file_destroy' unconditionally frees both names,
which is a double-free bug.

Fix this in the stupid way, by allocating a separate copy of the
filename if we duplicate the input filespec.  (I could fix it in
`file_destroy' instead, but that becomes a little fiddly, and it's
rather brittle.
file.c