diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-25 10:15:35 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-25 10:15:35 -0400 |
| commit | 7b7d84b3bea179d607fae2db5de7613adef1a6fd (patch) | |
| tree | 15ca8845b3dbbaec134ad8c997e10d69e73d28de /src | |
| parent | 5e583af9c55a5bdda6d0f699117a9df163f00b21 (diff) | |
| download | stasis-7b7d84b3bea179d607fae2db5de7613adef1a6fd.tar.gz | |
delivery_init_tmpdir: reverse error condition to clean up goto logic
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/delivery/delivery_init.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/lib/delivery/delivery_init.c b/src/lib/delivery/delivery_init.c index a163f01..9a2f6c3 100644 --- a/src/lib/delivery/delivery_init.c +++ b/src/lib/delivery/delivery_init.c @@ -12,7 +12,7 @@ int has_mount_flags(const char *mount_point, const unsigned long flags) { int delivery_init_tmpdir(struct Delivery *ctx) { char *tmpdir = NULL; char *x = NULL; - int unusable = 0; + int unusable = 1; errno = 0; x = getenv("TMPDIR"); @@ -25,7 +25,8 @@ int delivery_init_tmpdir(struct Delivery *ctx) { if (!tmpdir) { // memory error - return -1; + SYSERROR("%s", "unable to allocate tmpdir"); + goto l_delivery_init_tmpdir_fatal; } // If the directory doesn't exist, create it @@ -61,15 +62,25 @@ int delivery_init_tmpdir(struct Delivery *ctx) { if (!globals.tmpdir) { globals.tmpdir = strdup(tmpdir); + if (!globals.tmpdir) { + SYSERROR("%s", "unable to allocate globals.tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } if (!ctx->storage.tmpdir) { ctx->storage.tmpdir = strdup(globals.tmpdir); + if (!ctx->storage.tmpdir) { + SYSERROR("%s", "unable to allocate globals.tmpdir"); + goto l_delivery_init_tmpdir_fatal; + } } - return unusable; + unusable = 0; l_delivery_init_tmpdir_fatal: - unusable = 1; + if (unusable) { + guard_free(tmpdir); + } return unusable; } |
