changeset 5320:43bde2b01a59

6614232 results of zpool_validate_properties() are consistently leaked 6615080 zpool upgrade -V without a pool returns success
author lling
date Wed, 24 Oct 2007 13:53:20 -0700
parents 9240c6b7b6bd
children 0d8bd7d3764e
files usr/src/cmd/zpool/zpool_main.c usr/src/lib/libzfs/common/libzfs_pool.c
diffstat 2 files changed, 31 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/zpool/zpool_main.c	Wed Oct 24 13:35:35 2007 -0700
+++ b/usr/src/cmd/zpool/zpool_main.c	Wed Oct 24 13:53:20 2007 -0700
@@ -3204,7 +3204,6 @@
 	boolean_t showversions = B_FALSE;
 	char *end;
 
-	cb.cb_version = SPA_VERSION;
 
 	/* check options */
 	while ((c = getopt(argc, argv, "avV:")) != -1) {
@@ -3217,7 +3216,8 @@
 			break;
 		case 'V':
 			cb.cb_version = strtoll(optarg, &end, 10);
-			if (*end != '\0') {
+			if (*end != '\0' || cb.cb_version > SPA_VERSION ||
+			    cb.cb_version < SPA_VERSION_1) {
 				(void) fprintf(stderr,
 				    gettext("invalid version '%s'\n"), optarg);
 				usage(B_FALSE);
@@ -3235,6 +3235,14 @@
 	argc -= optind;
 	argv += optind;
 
+	if (cb.cb_version == 0) {
+		cb.cb_version = SPA_VERSION;
+	} else if (!cb.cb_all && argc == 0) {
+		(void) fprintf(stderr, gettext("-V option is "
+		    "incompatible with other arguments\n"));
+		usage(B_FALSE);
+	}
+
 	if (showversions) {
 		if (cb.cb_all || argc != 0) {
 			(void) fprintf(stderr, gettext("-v option is "
@@ -3243,8 +3251,8 @@
 		}
 	} else if (cb.cb_all) {
 		if (argc != 0) {
-			(void) fprintf(stderr, gettext("-a option is "
-			    "incompatible with other arguments\n"));
+			(void) fprintf(stderr, gettext("-a option should not "
+			    "be used along with a pool name\n"));
 			usage(B_FALSE);
 		}
 	}
--- a/usr/src/lib/libzfs/common/libzfs_pool.c	Wed Oct 24 13:35:35 2007 -0700
+++ b/usr/src/lib/libzfs/common/libzfs_pool.c	Wed Oct 24 13:53:20 2007 -0700
@@ -751,20 +751,24 @@
 	if (!zpool_name_valid(hdl, B_FALSE, pool))
 		return (zfs_error(hdl, EZFS_INVALIDNAME, msg));
 
+	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
+		return (-1);
+
 	if (props && (props = zpool_validate_properties(hdl, pool, props,
 	    SPA_VERSION_1, B_TRUE, msg)) == NULL)
 		return (-1);
 
-	if (zcmd_write_conf_nvlist(hdl, &zc, nvroot) != 0)
+	if (props && zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
+		nvlist_free(props);
 		return (-1);
-
-	if (props && zcmd_write_src_nvlist(hdl, &zc, props) != 0)
-		return (-1);
+	}
 
 	(void) strlcpy(zc.zc_name, pool, sizeof (zc.zc_name));
 
 	if (zfs_ioctl(hdl, ZFS_IOC_POOL_CREATE, &zc) != 0) {
+
 		zcmd_free_nvlists(&zc);
+		nvlist_free(props);
 
 		switch (errno) {
 		case EBUSY:
@@ -805,7 +809,6 @@
 			return (zpool_standard_error(hdl, errno, msg));
 		}
 	}
-	zcmd_free_nvlists(&zc);
 
 	/*
 	 * If this is an alternate root pool, then we automatically set the
@@ -822,6 +825,8 @@
 		zfs_close(zhp);
 	}
 
+	zcmd_free_nvlists(&zc);
+	nvlist_free(props);
 	return (0);
 }
 
@@ -1058,10 +1063,12 @@
 		    &version) == 0);
 
 		if ((props = zpool_validate_properties(hdl, origname,
-		    props, version, B_TRUE, errbuf)) == NULL)
+		    props, version, B_TRUE, errbuf)) == NULL) {
 			return (-1);
-		else if (zcmd_write_src_nvlist(hdl, &zc, props) != 0)
+		} else if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
+			nvlist_free(props);
 			return (-1);
+		}
 	}
 
 	(void) strlcpy(zc.zc_name, thename, sizeof (zc.zc_name));
@@ -1069,8 +1076,10 @@
 	verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID,
 	    &zc.zc_guid) == 0);
 
-	if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0)
+	if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) {
+		nvlist_free(props);
 		return (-1);
+	}
 
 	ret = 0;
 	if (zfs_ioctl(hdl, ZFS_IOC_POOL_IMPORT, &zc) != 0) {
@@ -1116,8 +1125,9 @@
 
 	}
 
-
 	zcmd_free_nvlists(&zc);
+	nvlist_free(props);
+
 	return (ret);
 }