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

Commit 4736a1bb authored by Dima Zavin's avatar Dima Zavin Committed by Android (Google) Code Review
Browse files

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

parents 6ac770fc 70b93034
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;