Commit 5e1611d0 authored by Philipp Schafft's avatar Philipp Schafft 🦁
Browse files

Update: Only run the unref stage if needed

parent 11974029
......@@ -364,6 +364,9 @@ igloo_error_t igloo_sp_replace(const char *str, const char **ref, igloo_ro_t ins
igloo_error_t error;
const char *ret;
if (!ref)
return igloo_ERROR_FAULT;
if (str == NULL) {
ret = NULL;
} else {
......@@ -372,10 +375,12 @@ igloo_error_t igloo_sp_replace(const char *str, const char **ref, igloo_ro_t ins
return error;
}
error = igloo_sp_unref(ref, instance);
if (error != igloo_ERROR_NONE) {
__ignore_error(igloo_sp_unref(&ret, instance));
return error;
if (*ref) {
error = igloo_sp_unref(ref, instance);
if (error != igloo_ERROR_NONE) {
__ignore_error(igloo_sp_unref(&ret, instance));
return error;
}
}
*ref = ret;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment