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
GitHub <noreply@github.com>Committed on Sep 23 2022, 5:51 PM
Parents
rGe9b12d4196c0: zpool: Don't print "repairing" on force faulted drives
Branches
Unknown
Tags
Unknown

Event Timeline

GitHub <noreply@github.com> committed rGd25153d55568: set_global_var_parse_kv() should pass the pointer from strdup() (authored by Richard Yao <richard.yao@alumni.stonybrook.edu>).Sep 23 2022, 5:51 PM