storage: Use VIR_AUTOPTR(virString)

Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
John Ferlan 2019-01-31 12:18:35 -05:00
parent 2f92d59c78
commit 1587ba7f62
3 changed files with 27 additions and 52 deletions

View File

@ -138,9 +138,9 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
{ {
int ret = -1; int ret = -1;
char *output = NULL; char *output = NULL;
char **lines = NULL;
char **cells = NULL;
size_t i; size_t i;
VIR_AUTOPTR(virString) lines = NULL;
VIR_AUTOPTR(virString) cells = NULL;
virCommandPtr cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", NULL); virCommandPtr cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", NULL);
virStorageBackendSheepdogAddHostArg(cmd, pool); virStorageBackendSheepdogAddHostArg(cmd, pool);
@ -173,8 +173,6 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
cleanup: cleanup:
virCommandFree(cmd); virCommandFree(cmd);
virStringListFree(lines);
virStringListFree(cells);
VIR_FREE(output); VIR_FREE(output);
return ret; return ret;
} }

View File

@ -104,13 +104,13 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
const char *volume_string) const char *volume_string)
{ {
int ret = -1; int ret = -1;
char **tokens;
size_t count; size_t count;
char **name_tokens = NULL;
char *vol_name; char *vol_name;
bool is_new_vol = false; bool is_new_vol = false;
virStorageVolDefPtr volume = NULL; virStorageVolDefPtr volume = NULL;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
VIR_AUTOPTR(virString) tokens = NULL;
VIR_AUTOPTR(virString) name_tokens = NULL;
if (!(tokens = virStringSplitCount(volume_string, "\t", 0, &count))) if (!(tokens = virStringSplitCount(volume_string, "\t", 0, &count)))
return -1; return -1;
@ -169,8 +169,6 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
ret = 0; ret = 0;
cleanup: cleanup:
virStringListFree(tokens);
virStringListFree(name_tokens);
if (is_new_vol) if (is_new_vol)
virStorageVolDefFree(volume); virStorageVolDefFree(volume);
return ret; return ret;
@ -183,8 +181,8 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
char *volumes_list = NULL; char *volumes_list = NULL;
char **lines = NULL;
size_t i; size_t i;
VIR_AUTOPTR(virString) lines = NULL;
/** /**
* $ zfs list -Hp -t volume -o name,volsize -r test * $ zfs list -Hp -t volume -o name,volsize -r test
@ -221,7 +219,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
cleanup: cleanup:
virCommandFree(cmd); virCommandFree(cmd);
virStringListFree(lines);
VIR_FREE(volumes_list); VIR_FREE(volumes_list);
return 0; return 0;
@ -233,9 +230,9 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED)
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
char *zpool_props = NULL; char *zpool_props = NULL;
char **lines = NULL;
char **tokens = NULL;
size_t i; size_t i;
VIR_AUTOPTR(virString) lines = NULL;
VIR_AUTOPTR(virString) tokens = NULL;
/** /**
* $ zpool get -Hp health,size,free,allocated test * $ zpool get -Hp health,size,free,allocated test
@ -296,8 +293,6 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED)
cleanup: cleanup:
virCommandFree(cmd); virCommandFree(cmd);
virStringListFree(lines);
virStringListFree(tokens);
VIR_FREE(zpool_props); VIR_FREE(zpool_props);
return 0; return 0;

View File

@ -1594,11 +1594,10 @@ virStorageFileParseBackingStoreStr(const char *str,
char **target, char **target,
unsigned int *chainIndex) unsigned int *chainIndex)
{ {
char **strings = NULL;
size_t nstrings; size_t nstrings;
unsigned int idx = 0; unsigned int idx = 0;
char *suffix; char *suffix;
int ret = -1; VIR_AUTOPTR(virString) strings = NULL;
*chainIndex = 0; *chainIndex = 0;
@ -1608,19 +1607,15 @@ virStorageFileParseBackingStoreStr(const char *str,
if (nstrings == 2) { if (nstrings == 2) {
if (virStrToLong_uip(strings[1], &suffix, 10, &idx) < 0 || if (virStrToLong_uip(strings[1], &suffix, 10, &idx) < 0 ||
STRNEQ(suffix, "]")) STRNEQ(suffix, "]"))
goto cleanup; return -1;
} }
if (target && if (target &&
VIR_STRDUP(*target, strings[0]) < 0) VIR_STRDUP(*target, strings[0]) < 0)
goto cleanup; return -1;
*chainIndex = idx; *chainIndex = idx;
ret = 0; return 0;
cleanup:
virStringListFreeCount(strings, nstrings);
return ret;
} }
@ -2677,8 +2672,8 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
{ {
virURIPtr uri = NULL; virURIPtr uri = NULL;
const char *path = NULL; const char *path = NULL;
char **scheme = NULL;
int ret = -1; int ret = -1;
VIR_AUTOPTR(virString) scheme = NULL;
if (!(uri = virURIParse(uristr))) { if (!(uri = virURIParse(uristr))) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -2772,7 +2767,6 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
cleanup: cleanup:
virURIFree(uri); virURIFree(uri);
virStringListFree(scheme);
return ret; return ret;
} }
@ -2783,7 +2777,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
{ {
char *port; char *port;
size_t skip; size_t skip;
char **parts; VIR_AUTOPTR(virString) parts = NULL;
if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0) if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0)
return -1; return -1;
@ -2808,7 +2802,6 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
if (!parts) if (!parts)
goto error; goto error;
src->hosts[src->nhosts-1].name = virStringListJoin((const char **)parts, ":"); src->hosts[src->nhosts-1].name = virStringListJoin((const char **)parts, ":");
virStringListFree(parts);
if (!src->hosts[src->nhosts-1].name) if (!src->hosts[src->nhosts-1].name)
goto error; goto error;
@ -2940,16 +2933,15 @@ static int
virStorageSourceParseNBDColonString(const char *nbdstr, virStorageSourceParseNBDColonString(const char *nbdstr,
virStorageSourcePtr src) virStorageSourcePtr src)
{ {
char **backing = NULL; VIR_AUTOPTR(virString) backing = NULL;
int ret = -1;
if (!(backing = virStringSplit(nbdstr, ":", 0))) if (!(backing = virStringSplit(nbdstr, ":", 0)))
goto cleanup; return -1;
/* we know that backing[0] now equals to "nbd" */ /* we know that backing[0] now equals to "nbd" */
if (VIR_ALLOC_N(src->hosts, 1) < 0) if (VIR_ALLOC_N(src->hosts, 1) < 0)
goto cleanup; return -1;
src->nhosts = 1; src->nhosts = 1;
src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
@ -2962,44 +2954,39 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing remote information in '%s' for protocol nbd"), _("missing remote information in '%s' for protocol nbd"),
nbdstr); nbdstr);
goto cleanup; return -1;
} else if (STREQ(backing[1], "unix")) { } else if (STREQ(backing[1], "unix")) {
if (!backing[2]) { if (!backing[2]) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing unix socket path in nbd backing string %s"), _("missing unix socket path in nbd backing string %s"),
nbdstr); nbdstr);
goto cleanup; return -1;
} }
if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0) if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0)
goto cleanup; return -1;
} else { } else {
if (VIR_STRDUP(src->hosts->name, backing[1]) < 0) if (VIR_STRDUP(src->hosts->name, backing[1]) < 0)
goto cleanup; return -1;
if (!backing[2]) { if (!backing[2]) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing port in nbd string '%s'"), _("missing port in nbd string '%s'"),
nbdstr); nbdstr);
goto cleanup; return -1;
} }
if (virStringParsePort(backing[2], &src->hosts->port) < 0) if (virStringParsePort(backing[2], &src->hosts->port) < 0)
goto cleanup; return -1;
} }
if (backing[3] && STRPREFIX(backing[3], "exportname=")) { if (backing[3] && STRPREFIX(backing[3], "exportname=")) {
if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=")) < 0) if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=")) < 0)
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
virStringListFree(backing);
return ret;
} }
@ -4250,9 +4237,8 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr top,
int int
virStorageFileCheckCompat(const char *compat) virStorageFileCheckCompat(const char *compat)
{ {
char **version;
unsigned int result; unsigned int result;
int ret = -1; VIR_AUTOPTR(virString) version = NULL;
if (!compat) if (!compat)
return 0; return 0;
@ -4263,13 +4249,9 @@ virStorageFileCheckCompat(const char *compat)
virStrToLong_ui(version[1], NULL, 10, &result) < 0) { virStrToLong_ui(version[1], NULL, 10, &result) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("forbidden characters in 'compat' attribute")); _("forbidden characters in 'compat' attribute"));
goto cleanup; return -1;
} }
ret = 0; return 0;
cleanup:
virStringListFree(version);
return ret;
} }