From: Matthew Fernandez Date: Sat, 2 Jul 2022 02:06:58 +0000 (-0700) Subject: agstrdup_internal: handle allocation failures X-Git-Tag: 5.0.0~3^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4328794734bee51656f3d64fcfe1842554237228;p=graphviz agstrdup_internal: handle allocation failures --- diff --git a/lib/cgraph/refstr.c b/lib/cgraph/refstr.c index 0bed41136..3921a4570 100644 --- a/lib/cgraph/refstr.c +++ b/lib/cgraph/refstr.c @@ -9,6 +9,7 @@ *************************************************************************/ #include +#include #include #include #include @@ -110,8 +111,12 @@ static char *agstrdup_internal(Agraph_t *g, const char *s, bool is_html) { sz = sizeof(refstr_t) + strlen(s); if (g) r = agalloc(g, sz); - else + else { r = malloc(sz); + if (UNLIKELY(sz > 0 && r == NULL)) { + return NULL; + } + } r->refcnt = 1; r->is_html = is_html; strcpy(r->store, s);