Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70b93034 authored by Dima Zavin's avatar Dima Zavin
Browse files

cutils: str_parms: need to also dup the key when adding to hash



Change-Id: Iabdd2061cbc36c6f4d4eb6e46bd757b5b52e0027
Signed-off-by: default avatarDima Zavin <dima@android.com>
parent 63d84d04
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -158,15 +158,18 @@ int str_parms_add_str(struct str_parms *str_parms, const char *key,
                      const char *value)
{
    void *old_val;
    char *tmp;
    void *tmp_key;
    void *tmp_val;

    tmp = strdup(value);
    old_val = hashmapPut(str_parms->map, (void *)key, tmp);
    tmp_key = strdup(key);
    tmp_val = strdup(value);
    old_val = hashmapPut(str_parms->map, tmp_key, tmp_val);

    if (old_val) {
        free(old_val);
    } else if (errno == ENOMEM) {
        free(tmp);
        free(tmp_key);
        free(tmp_val);
        return -ENOMEM;
    }
    return 0;