HomeFreeBSD

set_global_var_parse_kv() should pass the pointer from strdup()

Description

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 <ngompa@datto.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13867

Details

Provenance
Richard Yao <richard.yao@alumni.stonybrook.edu>Authored on Sep 23 2022, 5:51 PM
Tony Hutter <hutter2@llnl.gov>Committed on Dec 1 2022, 8:39 PM
Parents
rGfbe150fe5bb5: Call va_end() before return in zpool_standard_error_fmt()
Branches
Unknown
Tags
Unknown

Event Timeline

Tony Hutter <hutter2@llnl.gov> committed rGe11c4327f12d: set_global_var_parse_kv() should pass the pointer from strdup() (authored by Richard Yao <richard.yao@alumni.stonybrook.edu>).Dec 1 2022, 8:39 PM