summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 57b9e83)
raw | patch | inline | side by side (parent: 57b9e83)
author | Florian Forster <octo@collectd.org> | |
Mon, 15 May 2017 06:51:56 +0000 (08:51 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 15 May 2017 06:51:59 +0000 (08:51 +0200) |
The parameters are allocated with calloc(), freeing them with a library
function is unintuitive at best. Also, the library functions appears to
be missing the appropriate function attribute to tell clang / GCC that
it will free the pointer, resulting in a false-positive scan-build
report.
function is unintuitive at best. Also, the library functions appears to
be missing the appropriate function attribute to tell clang / GCC that
it will free the pointer, resulting in a false-positive scan-build
report.
src/virt.c | patch | blob | history |
diff --git a/src/virt.c b/src/virt.c
index a8f378a2d5b7bef38d859cad6f011f4bbd2f57d4..14095df45a68cba8c8b8497cbceece8901e0a15c 100644 (file)
--- a/src/virt.c
+++ b/src/virt.c
ret = virDomainGetCPUStats(dom, param, nparams, -1, 1, 0); // total stats.
if (ret < 0) {
- virTypedParamsFree(param, nparams);
+ virTypedParamsClear(param, nparams);
+ sfree(param);
VIRT_ERROR(conn, "getting the disk params values");
return -1;
}
info->total_syst_cpu_time = param[i].value.ul;
}
- virTypedParamsFree(param, nparams);
+ virTypedParamsClear(param, nparams);
+ sfree(param);
#endif /* HAVE_CPU_STATS */
return 0;
static int lv_domain_block_info(virDomainPtr dom, const char *path,
struct lv_block_info *binfo) {
#ifdef HAVE_BLOCK_STATS_FLAGS
- virTypedParameterPtr params = NULL;
int nparams = 0;
- int rc = -1;
- int ret = virDomainBlockStatsFlags(dom, path, NULL, &nparams, 0);
- if (ret < 0 || nparams == 0) {
+ if (virDomainBlockStatsFlags(dom, path, NULL, &nparams, 0) < 0 ||
+ nparams <= 0) {
VIRT_ERROR(conn, "getting the disk params count");
return -1;
}
- params = calloc(nparams, sizeof(virTypedParameter));
+ virTypedParameterPtr params = calloc((size_t)nparams, sizeof(*params));
if (params == NULL) {
ERROR("virt plugin: alloc(%i) for block=%s parameters failed.", nparams,
path);
return -1;
}
- ret = virDomainBlockStatsFlags(dom, path, params, &nparams, 0);
- if (ret < 0) {
+
+ int rc = -1;
+ if (virDomainBlockStatsFlags(dom, path, params, &nparams, 0) < 0) {
VIRT_ERROR(conn, "getting the disk params values");
- goto done;
+ } else {
+ rc = get_block_info(binfo, params, nparams);
}
- rc = get_block_info(binfo, params, nparams);
-
-done:
- virTypedParamsFree(params, nparams);
+ virTypedParamsClear(params, nparams);
+ sfree(params);
return rc;
#else
return virDomainBlockStats(dom, path, &(binfo->bi), sizeof(binfo->bi));
we can't detect this.
*/
#ifdef LIBVIR_CHECK_VERSION
-# if LIBVIR_CHECK_VERSION(0,10,2)
-# define HAVE_LIST_ALL_DOMAINS 1
-# endif
+#if LIBVIR_CHECK_VERSION(0, 10, 2)
+#define HAVE_LIST_ALL_DOMAINS 1
+#endif
#endif
static int refresh_lists(struct lv_read_instance *inst) {
if (n > 0) {
#ifdef HAVE_LIST_ALL_DOMAINS
virDomainPtr *domains;
- n = virConnectListAllDomains (conn, &domains, VIR_CONNECT_LIST_DOMAINS_ACTIVE);
+ n = virConnectListAllDomains(conn, &domains,
+ VIR_CONNECT_LIST_DOMAINS_ACTIVE);
#else
int *domids;
}
#ifdef HAVE_LIST_ALL_DOMAINS
- sfree (domains);
+ sfree(domains);
#else
sfree(domids);
#endif