diff options
| author | Dima Zavin <dima@android.com> | 2012-03-14 23:10:06 -0700 |
|---|---|---|
| committer | Dima Zavin <dima@android.com> | 2012-03-14 23:17:11 -0700 |
| commit | 86bfbe3cae1f5e480ba9756ec7404fa4d5a7f2c9 (patch) | |
| tree | 83a72736c451f9eb6c942b1de9c23d9378dbd0f5 /libcutils | |
| parent | 820571f4c3f2b95145269d5aa8afe117713a7ce1 (diff) | |
| download | system_core-86bfbe3cae1f5e480ba9756ec7404fa4d5a7f2c9.tar.gz system_core-86bfbe3cae1f5e480ba9756ec7404fa4d5a7f2c9.tar.bz2 system_core-86bfbe3cae1f5e480ba9756ec7404fa4d5a7f2c9.zip | |
cutils: str_parms: free the key if the value was replaced during create/add
Change-Id: I9f31da62f10f78ed11693a7c04e2be29b0790c93
Reported-by: Xin Qian <xqian@marvell.com>
Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'libcutils')
| -rw-r--r-- | libcutils/str_parms.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libcutils/str_parms.c b/libcutils/str_parms.c index 16138f6b..364695c2 100644 --- a/libcutils/str_parms.c +++ b/libcutils/str_parms.c @@ -128,8 +128,10 @@ struct str_parms *str_parms_create_str(const char *_string) /* if we replaced a value, free it */ old_val = hashmapPut(str_parms->map, key, value); - if (old_val) + if (old_val) { free(old_val); + free(key); + } items++; next_pair: @@ -167,6 +169,7 @@ int str_parms_add_str(struct str_parms *str_parms, const char *key, if (old_val) { free(old_val); + free(tmp_key); } else if (errno == ENOMEM) { free(tmp_key); free(tmp_val); @@ -327,6 +330,7 @@ int main(void) test_str_parms_str("foo=bar;baz="); test_str_parms_str("foo=bar;baz=bat"); test_str_parms_str("foo=bar;baz=bat;"); + test_str_parms_str("foo=bar;baz=bat;foo=bar"); return 0; } |
