diff options
author | eschrock <none@none> | 2006-06-07 11:54:54 -0700 |
---|---|---|
committer | eschrock <none@none> | 2006-06-07 11:54:54 -0700 |
commit | 94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51 (patch) | |
tree | 600a2d2b5c089c0cfb4d32503f23acadd2b625aa /usr/src/lib/libzfs/common/libzfs_pool.c | |
parent | 62d717f5277d7b19b63db2d800310f877b57c197 (diff) | |
download | illumos-gate-94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51.tar.gz |
6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
6433406 zfs_open() can leak memory on failure
6433408 namespace_reload() can leak memory on allocation failure
6433679 zpool_refresh_stats() has poor error semantics
6433680 changelist_gather() ignores libuutil errors
Diffstat (limited to 'usr/src/lib/libzfs/common/libzfs_pool.c')
-rw-r--r-- | usr/src/lib/libzfs/common/libzfs_pool.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/usr/src/lib/libzfs/common/libzfs_pool.c b/usr/src/lib/libzfs/common/libzfs_pool.c index 37c82015b9..dc25ea6d17 100644 --- a/usr/src/lib/libzfs/common/libzfs_pool.c +++ b/usr/src/lib/libzfs/common/libzfs_pool.c @@ -154,6 +154,7 @@ zpool_handle_t * zpool_open_canfail(libzfs_handle_t *hdl, const char *pool) { zpool_handle_t *zhp; + boolean_t missing; /* * Make sure the pool name is valid. @@ -171,20 +172,19 @@ zpool_open_canfail(libzfs_handle_t *hdl, const char *pool) zhp->zpool_hdl = hdl; (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name)); - if (zpool_refresh_stats(zhp) != 0) { - if (errno == ENOENT || errno == EINVAL) { - zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, - "no such pool")); - (void) zfs_error(hdl, EZFS_NOENT, - dgettext(TEXT_DOMAIN, "cannot open '%s'"), - pool); - free(zhp); - return (NULL); - } else { - zhp->zpool_state = POOL_STATE_UNAVAIL; - } - } else { - zhp->zpool_state = POOL_STATE_ACTIVE; + if (zpool_refresh_stats(zhp, &missing) != 0) { + zpool_close(zhp); + return (NULL); + } + + if (missing) { + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "no such pool")); + (void) zfs_error(hdl, EZFS_NOENT, + dgettext(TEXT_DOMAIN, "cannot open '%s'"), + pool); + zpool_close(zhp); + return (NULL); } return (zhp); @@ -194,29 +194,31 @@ zpool_open_canfail(libzfs_handle_t *hdl, const char *pool) * Like the above, but silent on error. Used when iterating over pools (because * the configuration cache may be out of date). */ -zpool_handle_t * -zpool_open_silent(libzfs_handle_t *hdl, const char *pool) +int +zpool_open_silent(libzfs_handle_t *hdl, const char *pool, zpool_handle_t **ret) { zpool_handle_t *zhp; + boolean_t missing; - if ((zhp = calloc(sizeof (zpool_handle_t), 1)) == NULL) - return (NULL); + if ((zhp = zfs_alloc(hdl, sizeof (zpool_handle_t))) == NULL) + return (-1); zhp->zpool_hdl = hdl; (void) strlcpy(zhp->zpool_name, pool, sizeof (zhp->zpool_name)); - if (zpool_refresh_stats(zhp) != 0) { - if (errno == ENOENT || errno == EINVAL) { - free(zhp); - return (NULL); - } else { - zhp->zpool_state = POOL_STATE_UNAVAIL; - } - } else { - zhp->zpool_state = POOL_STATE_ACTIVE; + if (zpool_refresh_stats(zhp, &missing) != 0) { + zpool_close(zhp); + return (-1); } - return (zhp); + if (missing) { + zpool_close(zhp); + *ret = NULL; + return (0); + } + + *ret = zhp; + return (0); } /* @@ -708,7 +710,9 @@ zpool_import(libzfs_handle_t *hdl, nvlist_t *config, const char *newname, /* * This should never fail, but play it safe anyway. */ - if ((zhp = zpool_open_silent(hdl, thename)) != NULL) { + if (zpool_open_silent(hdl, thename, &zhp) != 0) { + ret = -1; + } else if (zhp != NULL) { ret = zpool_create_zvol_links(zhp); zpool_close(zhp); } |