Skip to content

Commit

Permalink
Fix allocation errors, detected using ASAN
Browse files Browse the repository at this point in the history
The test for VDEV_TYPE_INDIRECT is done after a memory allocation, and
could return from function without freeing it.  Since we don't need that
allocation yet, just postpone it.

Add a missing free() when buffer is no longer needed.

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: João Carlos Mendes Luís <jonny@jonny.eng.br>
Closes openzfs#10193 
(cherry picked from commit 75c6201)
  • Loading branch information
dioni21 authored and as-com committed Jun 20, 2020
1 parent 3b15067 commit b70267e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4395,11 +4395,11 @@ print_vdev_stats(zpool_handle_t *zhp, const char *name, nvlist_t *oldnv,
uint64_t tdelta;
double scale;

calcvs = safe_malloc(sizeof (*calcvs));

if (strcmp(name, VDEV_TYPE_INDIRECT) == 0)
return (ret);

calcvs = safe_malloc(sizeof (*calcvs));

if (oldnv != NULL) {
verify(nvlist_lookup_uint64_array(oldnv,
ZPOOL_CONFIG_VDEV_STATS, (uint64_t **)&oldvs, &c) == 0);
Expand Down Expand Up @@ -7387,6 +7387,7 @@ print_removal_status(zpool_handle_t *zhp, pool_removal_stat_t *prs)
", (copy is slow, no estimated time)\n"));
}
}
free(vdev_name);

if (prs->prs_mapping_memory > 0) {
char mem_buf[7];
Expand Down

0 comments on commit b70267e

Please sign in to comment.