Commit 37abfec
committed
cli: fix memory leak in volume status detail (#4292)
gf_cli_status_cbk() never freed the heap strings status.free and
status.total returned by gf_uint64_2human_readable() via gf_asprintf().
Each invocation of `gluster volume status all detail` leaked two
strings per brick reported. The reporter's ASan trace confirms 144
bytes leaked in 4 allocations (2 calls x 2 bricks).
The other string fields in cli_volume_status_t (fs_name, mount_options,
device, inode_size) are borrowed pointers from dict_get_str() — they
are released by dict_unref() at the out: label and must NOT be freed
per-field.
Also fix a pre-existing leak of status.pid_str on the
cli_get_detail_status() error path: if cli_get_detail_status() fails
(goto out after line 7597), pid_str is already allocated via
gf_asprintf() but the out: label never freed it. The gf_asprintf
failure path at line 7592 cannot leak pid_str because gf_vasprintf()
does not write *string_ptr on allocation failure — the pointer stays
NULL from the {0} initializer.
Since GF_FREE() does not NULL the freed pointer, all per-iteration
pointers are explicitly NULLed after freeing to prevent double-free
when the normal path falls through to out:.
Fixes: #4292
Signed-off-by: Thales Antunes de Oliveira Barretto <thales.barretto.git@gmail.com>1 parent ae1d696 commit 37abfec
1 file changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7601 | 7601 | | |
7602 | 7602 | | |
7603 | 7603 | | |
7604 | | - | |
7605 | 7604 | | |
| 7605 | + | |
| 7606 | + | |
| 7607 | + | |
| 7608 | + | |
| 7609 | + | |
7606 | 7610 | | |
7607 | 7611 | | |
7608 | 7612 | | |
| |||
7615 | 7619 | | |
7616 | 7620 | | |
7617 | 7621 | | |
| 7622 | + | |
| 7623 | + | |
| 7624 | + | |
7618 | 7625 | | |
7619 | 7626 | | |
7620 | 7627 | | |
| |||
0 commit comments