From 672cdfa07cf83fec396836cbe1ba1415e5764ebf Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 4 Feb 2025 09:33:18 -0500 Subject: Improve message on memory error --- src/lib/delivery/delivery_populate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/delivery/delivery_populate.c') diff --git a/src/lib/delivery/delivery_populate.c b/src/lib/delivery/delivery_populate.c index e9aea89..f14016a 100644 --- a/src/lib/delivery/delivery_populate.c +++ b/src/lib/delivery/delivery_populate.c @@ -34,7 +34,7 @@ int populate_info(struct Delivery *ctx) { ctx->info.time_str_epoch = calloc(STASIS_TIME_STR_MAX, sizeof(*ctx->info.time_str_epoch)); if (!ctx->info.time_str_epoch) { - msg(STASIS_MSG_ERROR, "Unable to allocate memory for Unix epoch string\n"); + msg(STASIS_MSG_ERROR, "%s: Unable to allocate memory for Unix epoch string\n", strerror(errno)); return -1; } snprintf(ctx->info.time_str_epoch, STASIS_TIME_STR_MAX - 1, "%li", ctx->info.time_now); -- cgit From 78ded5bc427eba89e425064e38b63dd65a4c679b Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 4 Feb 2025 09:36:14 -0500 Subject: Replace localtime with localtime_r and allocate a new buffer for each Delivery context --- src/lib/delivery/delivery_populate.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/lib/delivery/delivery_populate.c') diff --git a/src/lib/delivery/delivery_populate.c b/src/lib/delivery/delivery_populate.c index f14016a..63df9fd 100644 --- a/src/lib/delivery/delivery_populate.c +++ b/src/lib/delivery/delivery_populate.c @@ -30,7 +30,17 @@ int populate_info(struct Delivery *ctx) { if (!ctx->info.time_str_epoch) { // Record timestamp used for release time(&ctx->info.time_now); - ctx->info.time_info = localtime(&ctx->info.time_now); + if (!ctx->info.time_info) { + ctx->info.time_info = malloc(sizeof(*ctx->info.time_info)); + if (!ctx->info.time_info) { + msg(STASIS_MSG_ERROR, "%s: Unable to allocate memory for time_info\n", strerror(errno)); + return -1; + } + if (!localtime_r(&ctx->info.time_now, ctx->info.time_info)) { + msg(STASIS_MSG_ERROR, "%s: localtime_r failed\n", strerror(errno)); + return -1; + } + } ctx->info.time_str_epoch = calloc(STASIS_TIME_STR_MAX, sizeof(*ctx->info.time_str_epoch)); if (!ctx->info.time_str_epoch) { -- cgit