summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRichard Yao <[email protected]>2022-09-23 13:51:14 -0400
committerTony Hutter <[email protected]>2022-12-01 12:39:41 -0800
commite11c4327f12df0e1f3ae9a9187a7ee553d1d6e95 (patch)
treea9483b9cb11d02665648ccb579be1e77d9622641 /lib
parentfbe150fe5bb58a5086040c15ab186a55b61bc8ca (diff)
set_global_var_parse_kv() should pass the pointer from strdup()
A comment says that the caller should free k_out, but the pointer passed via k_out is not the same pointer we received from strdup(). Instead, it is a pointer into the region we received from strdup(). The free function should always be called with the original pointer, so this is likely a bug. We solve this by calling `strdup()` a second time and then freeing the original pointer. Coverity reported this as a memory leak. Reviewed-by: Neal Gompa <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Richard Yao <[email protected]> Closes #13867
Diffstat (limited to 'lib')
-rw-r--r--lib/libzpool/util.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/libzpool/util.c b/lib/libzpool/util.c
index 20cabe7c2..327391245 100644
--- a/lib/libzpool/util.c
+++ b/lib/libzpool/util.c
@@ -173,12 +173,13 @@ set_global_var_parse_kv(const char *arg, char **k_out, u_longlong_t *v_out)
goto err_free;
}
- *k_out = k;
+ *k_out = strdup(k);
*v_out = val;
+ free(d);
return (0);
err_free:
- free(k);
+ free(d);
return (err);
}