From 3bf2a275665e0d2a5145e94358618a6dc2f6089d Mon Sep 17 00:00:00 2001 From: Benjamin Kaduk Date: Sun, 11 Aug 2024 15:57:05 -0700 Subject: [PATCH] bosserver: use normal asprintf idiom We generally tend to explicitly NULL out the buffer argument if asprintf() returns failure, since it is not guaranteed to have done so itself. It is even less clear whether setting the buffer argument to NULL ourselves before calling asprintf() will be untouched in all possible failures, so re-zero it after failed calls just to be sure we don't try to free garbage later. Change-Id: Ie8995472aeadb8043f5e43f4e6d197a7be1363e0 Reviewed-on: https://gerrit.openafs.org/15832 Tested-by: BuildBot Reviewed-by: Michael Meffie --- src/bozo/bosserver.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bozo/bosserver.c b/src/bozo/bosserver.c index 6cfe29f405..95eb8791bc 100644 --- a/src/bozo/bosserver.c +++ b/src/bozo/bosserver.c @@ -713,14 +713,18 @@ make_pid_filename(char *ainst, char *aname) if (aname && *aname) { r = asprintf(&buffer, "%s/%s.%s.pid", DoPidFiles, ainst, aname); - if (r < 0 || buffer == NULL) + if (r < 0 || buffer == NULL) { ViceLog(0, ("Failed to alloc pid filename buffer for %s.%s.\n", ainst, aname)); + buffer = NULL; + } } else { r = asprintf(&buffer, "%s/%s.pid", DoPidFiles, ainst); - if (r < 0 || buffer == NULL) + if (r < 0 || buffer == NULL) { ViceLog(0, ("Failed to alloc pid filename buffer for %s.\n", ainst)); + buffer = NULL; + } } return buffer;