Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: handle ENOMEM gracefully during logging #5536

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/core/out.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2021, Intel Corporation */
/* Copyright 2014-2023, Intel Corporation */

/*
* out.c -- support for logging, tracing, and assertion output
Expand Down Expand Up @@ -91,7 +91,7 @@ Last_errormsg_get(void)
if (errormsg == NULL) {
errormsg = malloc(sizeof(struct errormsg));
if (errormsg == NULL)
FATAL("!malloc");
return NULL;
/* make sure it contains empty string initially */
errormsg->msg[0] = '\0';
int ret = os_tls_set(Last_errormsg_key, errormsg);
Expand Down Expand Up @@ -425,6 +425,11 @@ out_error(const char *file, int line, const char *func,

char *errormsg = (char *)out_get_errormsg();

if (errormsg == NULL) {
Print("There's no memory to properly format error strings.");
return;
}

if (fmt) {
if (*fmt == '!') {
sep = ": ";
Expand Down