From e22e5d63b9bdab5342dd921572ab9e70d8db0b14 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Sat, 12 Oct 2024 08:05:28 +0100 Subject: [PATCH] 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. --- utils/flock.c | 4 ++-- utils/path.c | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/utils/flock.c b/utils/flock.c index 5117bc99..56b44258 100644 --- a/utils/flock.c +++ b/utils/flock.c @@ -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; } diff --git a/utils/path.c b/utils/path.c index 3a0fea80..d82dbb55 100644 --- a/utils/path.c +++ b/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);