goto cleanup;
}
- if (VIR_ALLOC_N(infolist, n) < 0) {
+ /* null-terminated list */
+ if (VIR_ALLOC_N(infolist, n + 1) < 0) {
virReportOOMError();
goto cleanup;
}
goto cleanup;
}
- if (VIR_ALLOC_N(cpulist, n) < 0) {
+ /* null-terminated list */
+ if (VIR_ALLOC_N(cpulist, n + 1) < 0) {
virReportOOMError();
goto cleanup;
}
*cpus = cpulist;
cleanup:
- if (ret < 0 && cpulist) {
- for (i = 0 ; i < n ; i++)
- VIR_FREE(cpulist[i]);
- VIR_FREE(cpulist);
- }
+ if (ret < 0)
+ virStringFreeList(cpulist);
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
goto cleanup;
}
- if (VIR_ALLOC_N(commandlist, n) < 0) {
+ /* null-terminated list */
+ if (VIR_ALLOC_N(commandlist, n + 1) < 0) {
virReportOOMError();
goto cleanup;
}
*commands = commandlist;
cleanup:
- if (ret < 0 && commandlist) {
- for (i = 0 ; i < n ; i++)
- VIR_FREE(commandlist[i]);
- VIR_FREE(commandlist);
- }
+ if (ret < 0)
+ virStringFreeList(commandlist);
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
goto cleanup;
}
- if (VIR_ALLOC_N(eventlist, n) < 0) {
+ /* null-terminated list */
+ if (VIR_ALLOC_N(eventlist, n + 1) < 0) {
virReportOOMError();
goto cleanup;
}
*events = eventlist;
cleanup:
- if (ret < 0 && eventlist) {
- for (i = 0 ; i < n ; i++)
- VIR_FREE(eventlist[i]);
- VIR_FREE(eventlist);
- }
+ if (ret < 0)
+ virStringFreeList(eventlist);
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
goto cleanup;
}
- if (VIR_ALLOC_N(typelist, n) < 0) {
+ /* null-terminated list */
+ if (VIR_ALLOC_N(typelist, n + 1) < 0) {
virReportOOMError();
goto cleanup;
}
*types = typelist;
cleanup:
- if (ret < 0 && typelist) {
- for (i = 0 ; i < n ; i++)
- VIR_FREE(typelist[i]);
- VIR_FREE(typelist);
- }
+ if (ret < 0)
+ virStringFreeList(typelist);
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;
goto cleanup;
}
- if (VIR_ALLOC_N(proplist, n) < 0) {
+ /* null-terminated list */
+ if (VIR_ALLOC_N(proplist, n + 1) < 0) {
virReportOOMError();
goto cleanup;
}
*props = proplist;
cleanup:
- if (ret < 0 && proplist) {
- for (i = 0 ; i < n ; i++)
- VIR_FREE(proplist[i]);
- VIR_FREE(proplist);
- }
+ if (ret < 0)
+ virStringFreeList(proplist);
virJSONValueFree(cmd);
virJSONValueFree(reply);
return ret;