aboutsummaryrefslogtreecommitdiffstats
path: root/src/env.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-09-10 11:50:45 -0400
committerDavid Robillard <d@drobilla.net>2023-09-22 23:54:50 -0400
commit031decbb82f34313a2403e8852ce630b573eb177 (patch)
treea4b564638bb4462a2b6bec5eaa65274a0ac44f40 /src/env.c
parentaf1d31f6ee9d822d85087ad03ad8b2cee5a36744 (diff)
downloadserd-031decbb82f34313a2403e8852ce630b573eb177.tar.gz
serd-031decbb82f34313a2403e8852ce630b573eb177.tar.bz2
serd-031decbb82f34313a2403e8852ce630b573eb177.zip
Fix potential realloc leaks
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c9
1 files changed, 6 insertions, 3 deletions
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);
+ }
}
}