From: Denys Vlasenko Date: Tue, 5 Mar 2013 16:29:18 +0000 (+0100) Subject: strace_vfprintf: if malloc fails, exit gracefully X-Git-Tag: v4.8~101 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dafba9bb99ecee458fc7f6cd37151ae1c91ae522;p=strace strace_vfprintf: if malloc fails, exit gracefully Signed-off-by: Denys Vlasenko --- diff --git a/vsprintf.c b/vsprintf.c index b66609ac..f6019f0e 100644 --- a/vsprintf.c +++ b/vsprintf.c @@ -759,8 +759,8 @@ int kernel_vsnprintf(char *buf, size_t size, const char *fmt, va_list args) int strace_vfprintf(FILE *fp, const char *fmt, va_list args) { - static char *buf; - static unsigned buflen; + static char *buf = NULL; + static unsigned buflen = 0; int r; va_list a1; @@ -773,6 +773,8 @@ int strace_vfprintf(FILE *fp, const char *fmt, va_list args) buflen = len + 256; free(buf); buf = malloc(buflen); + if (!buf) + die_out_of_memory(); /*len =*/ kernel_vsnprintf(buf, buflen, fmt, args); }