From 031decbb82f34313a2403e8852ce630b573eb177 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 10 Sep 2023 11:50:45 -0400 Subject: Fix potential realloc leaks --- src/env.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/env.c') diff --git a/src/env.c b/src/env.c index 7a9ae8fa..3d560c98 100644 --- a/src/env.c +++ b/src/env.c @@ -119,10 +119,13 @@ serd_env_add(SerdEnv* const env, serd_node_free(&old_prefix_uri); } } else { - env->prefixes = (SerdPrefix*)realloc( + SerdPrefix* const new_prefixes = (SerdPrefix*)realloc( env->prefixes, (++env->n_prefixes) * sizeof(SerdPrefix)); - env->prefixes[env->n_prefixes - 1].name = serd_node_copy(name); - env->prefixes[env->n_prefixes - 1].uri = serd_node_copy(uri); + if (new_prefixes) { + env->prefixes = new_prefixes; + env->prefixes[env->n_prefixes - 1].name = serd_node_copy(name); + env->prefixes[env->n_prefixes - 1].uri = serd_node_copy(uri); + } } } -- cgit v1.2.1