Fix memory leak in pw_properties_set

removing a property leaked the key
This commit is contained in:
Jesse Pullinen 2018-08-30 19:40:40 +03:00 committed by Wim Taymans
parent db277bebb6
commit 1754438dc9

View file

@ -247,13 +247,13 @@ void pw_properties_free(struct pw_properties *properties)
free(impl);
}
static int do_replace(struct pw_properties *properties, char *key, char *value)
static int do_replace(struct pw_properties *properties, const char *key, char *value)
{
struct properties *impl = SPA_CONTAINER_OF(properties, struct properties, this);
int index = find_index(properties, key);
if (index == -1) {
add_func(properties, key, value);
add_func(properties, strdup(key), value);
} else {
struct spa_dict_item *item =
pw_array_get_unchecked(&impl->items, index, struct spa_dict_item);
@ -267,7 +267,7 @@ static int do_replace(struct pw_properties *properties, char *key, char *value)
item->value = other->value;
impl->items.size -= sizeof(struct spa_dict_item);
} else {
item->key = key;
item->key = strdup(key);
item->value = value;
}
}
@ -288,7 +288,7 @@ static int do_replace(struct pw_properties *properties, char *key, char *value)
*/
int pw_properties_set(struct pw_properties *properties, const char *key, const char *value)
{
return do_replace(properties, strdup(key), value ? strdup(value) : NULL);
return do_replace(properties, key, value ? strdup(value) : NULL);
}
int
@ -297,7 +297,7 @@ pw_properties_setva(struct pw_properties *properties,
{
char *value;
vasprintf(&value, format, args);
return do_replace(properties, strdup(key), value);
return do_replace(properties, key, value);
}
/** Set a property value by format