ret = true;
cleanup:
- if (arr) {
- VIR_FREE(*arr);
- VIR_FREE(arr);
- }
+ virStringFreeList(arr);
virNodeDeviceFree(dev);
return ret;
}
vshError(ctl, "%s", _("Options --tree and --cap are incompatible"));
return false;
}
- ncaps = vshStringToArray(cap_str, &caps);
+ if ((ncaps = vshStringToArray(cap_str, &caps)) < 0)
+ return false;
}
for (i = 0; i < ncaps; i++) {
}
cleanup:
- if (caps) {
- VIR_FREE(*caps);
- VIR_FREE(caps);
- }
+ virStringFreeList(caps);
vshNodeDeviceListFree(list);
return ret;
}
ret = true;
cleanup:
- if (arr) {
- VIR_FREE(*arr);
- VIR_FREE(arr);
- }
+ virStringFreeList(arr);
VIR_FREE(xml);
virNodeDeviceFree(device);
return ret;
char **poolTypes = NULL;
int npoolTypes = 0;
- npoolTypes = vshStringToArray(type, &poolTypes);
+ if ((npoolTypes = vshStringToArray(type, &poolTypes)) < 0)
+ return false;
for (i = 0; i < npoolTypes; i++) {
if ((poolType = virStoragePoolTypeFromString(poolTypes[i])) < 0) {
vshError(ctl, "%s", _("Invalid pool type"));
- VIR_FREE(poolTypes);
+ virStringFreeList(poolTypes);
return false;
}
break;
}
}
- if (poolTypes) {
- VIR_FREE(*poolTypes);
- VIR_FREE(poolTypes);
- }
+ virStringFreeList(poolTypes);
}
if (!(list = vshStoragePoolListCollect(ctl, flags)))
cleanup:
if (ret < 0)
vshError(ctl, _("unable to parse memspec: %s"), str);
- if (array) {
- VIR_FREE(*array);
- VIR_FREE(array);
- }
+ virStringFreeList(array);
return ret;
}
cleanup:
if (ret < 0)
vshError(ctl, _("unable to parse diskspec: %s"), str);
- if (array) {
- VIR_FREE(*array);
- VIR_FREE(array);
- }
+ virStringFreeList(array);
return ret;
}
}
/*
- * Convert the strings separated by ',' into array. The caller
- * must free the first array element and the returned array after
- * use (all other array elements belong to the memory allocated
- * for the first array element).
+ * Convert the strings separated by ',' into array. The returned
+ * array is a NULL terminated string list. The caller has to free
+ * the array using virStringFreeList or a similar method.
*
* Returns the length of the filled array on success, or -1
* on error.
str_tok++;
}
- if (VIR_ALLOC_N(arr, nstr_tokens) < 0) {
+ /* reserve the NULL element at the end */
+ if (VIR_ALLOC_N(arr, nstr_tokens + 1) < 0) {
VIR_FREE(str_copied);
return -1;
}
continue;
}
*tmp++ = '\0';
- arr[nstr_tokens++] = str_tok;
+ arr[nstr_tokens++] = vshStrdup(NULL, str_tok);
str_tok = tmp;
}
- arr[nstr_tokens++] = str_tok;
+ arr[nstr_tokens++] = vshStrdup(NULL, str_tok);
*array = arr;
+ VIR_FREE(str_copied);
return nstr_tokens;
}
# include "virerror.h"
# include "virthread.h"
# include "virnetdevbandwidth.h"
+# include "virstring.h"
# define VSH_MAX_XML_FILE (10*1024*1024)