From 5804dd3f9b2740beaf1b2d75761fa44bc950c0c5 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 21 Dec 2020 19:48:55 +0100 Subject: [PATCH] properties: fix leak with NULL or empty key See #497 --- src/pipewire/properties.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pipewire/properties.c b/src/pipewire/properties.c index 9d259cc67..3de43e8e9 100644 --- a/src/pipewire/properties.c +++ b/src/pipewire/properties.c @@ -387,7 +387,7 @@ static int do_replace(struct pw_properties *properties, const char *key, char *v int index; if (key == NULL || key[0] == 0) - return 0; + goto exit_noupdate; index = find_index(properties, key); @@ -399,11 +399,8 @@ static int do_replace(struct pw_properties *properties, const char *key, char *v struct spa_dict_item *item = pw_array_get_unchecked(&impl->items, index, struct spa_dict_item); - if (value && strcmp(item->value, value) == 0) { - if (!copy) - free(value); - return 0; - } + if (value && strcmp(item->value, value) == 0) + goto exit_noupdate; if (value == NULL) { struct spa_dict_item *last = pw_array_get_unchecked(&impl->items, @@ -420,6 +417,10 @@ static int do_replace(struct pw_properties *properties, const char *key, char *v } } return 1; +exit_noupdate: + if (!copy) + free(value); + return 0; } /** Set a property value