PaCheckCompressed() removed API quirkiness
When constifying there is this inconsistent quirk in this API returning 'filename' or a malloced storage. When special handling needs to be made by the caller to detect this to decide if it needs a free. This appears to done to save a strdup(). Make it always return a malloc block so the API contract is strightforward to the caller. A non-NULL return requires free() by the caller.
This commit is contained in:
parent
e7bfa72298
commit
e22e5d63b9
|
|
@ -129,7 +129,7 @@ gzFile flock_zopen(filename, mode, is_locked, fdp)
|
|||
|
||||
fd = open(fname, oflag);
|
||||
if (fdp != NULL) *fdp = fd;
|
||||
if (fname != filename) freeMagic(fname);
|
||||
freeMagic(fname);
|
||||
return gzdopen(fd, mode);
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ gzFile flock_zopen(filename, mode, is_locked, fdp)
|
|||
|
||||
done:
|
||||
if (fdp != NULL) *fdp = fd;
|
||||
if (fname != filename) freeMagic(fname);
|
||||
freeMagic(fname);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
|
|||
11
utils/path.c
11
utils/path.c
|
|
@ -70,10 +70,10 @@ bool FileLocking = TRUE;
|
|||
* attempting to open the file.
|
||||
*
|
||||
* Return value:
|
||||
* The string value that resulted in a valid file descriptor.
|
||||
* This is a dynamically allocated string *or* a pointer to the
|
||||
* original filename; the calling routine should check and
|
||||
* free if needed.
|
||||
* The string value that resulted in a valid file descriptor
|
||||
* (a file that could be opened using that filename).
|
||||
* Return value is a dynamically allocated string the calling
|
||||
* routine should free.
|
||||
*
|
||||
*-------------------------------------------------------------------
|
||||
*/
|
||||
|
|
@ -91,8 +91,7 @@ PaCheckCompressed(filename)
|
|||
fd = open(gzname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
freeMagic(gzname);
|
||||
gzname = filename;
|
||||
strcpy(gzname, filename); /* always shorter than allocation */
|
||||
}
|
||||
else
|
||||
close(fd);
|
||||
|
|
|
|||
Loading…
Reference in New Issue