aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-08-12 16:40:31 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:59 +0100
commit722d2e1353641c9be3adee51b20bd99a76201742 (patch)
treea653142268ba7d478e70abf0aeab52d88ba463a5
parent8527574f88de6402954393bd6b2d6c8a93d7d7ef (diff)
downloadserd-722d2e1353641c9be3adee51b20bd99a76201742.tar.gz
serd-722d2e1353641c9be3adee51b20bd99a76201742.tar.bz2
serd-722d2e1353641c9be3adee51b20bd99a76201742.zip
Remove double allocation in serd_env_set_prefix()
-rw-r--r--src/env.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/env.c b/src/env.c
index 3dc89ac3..36d05d77 100644
--- a/src/env.c
+++ b/src/env.c
@@ -158,23 +158,20 @@ serd_env_find(const SerdEnv* env,
}
static void
-serd_env_add(SerdEnv* env,
- const SerdNode* name,
- const SerdNode* uri)
+serd_env_add(SerdEnv* env, const SerdNode* name, SerdNode* uri)
{
const char* name_str = serd_node_string(name);
SerdPrefix* const prefix = serd_env_find(env, name_str, name->n_bytes);
if (prefix) {
if (!serd_node_equals(prefix->uri, uri)) {
- SerdNode* old_prefix_uri = prefix->uri;
- prefix->uri = serd_node_copy(uri);
- serd_node_free(old_prefix_uri);
+ serd_node_free(prefix->uri);
+ prefix->uri = uri;
}
} else {
env->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);
+ env->prefixes[env->n_prefixes - 1].uri = uri;
}
}
@@ -187,7 +184,7 @@ serd_env_set_prefix(SerdEnv* env,
return SERD_ERR_BAD_ARG;
} else if (serd_uri_string_has_scheme(serd_node_string(uri))) {
// Set prefix to absolute URI
- serd_env_add(env, name, uri);
+ serd_env_add(env, name, serd_node_copy(uri));
} else if (!env->base_uri_node) {
return SERD_ERR_BAD_ARG;
} else {
@@ -197,7 +194,6 @@ serd_env_set_prefix(SerdEnv* env,
// Set prefix to resolved (absolute) URI
serd_env_add(env, name, abs_uri);
- serd_node_free(abs_uri);
}
return SERD_SUCCESS;
}