From: Dmitry Guryanov Date: Tue, 4 Dec 2012 13:43:06 +0000 (+0400) Subject: parallels: fix leaks in parallelsFindVolumes X-Git-Tag: v1.0.1-rc1~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7abe342d96e85fe2caf1e6a40f3ad802bbe22c30;p=thirdparty%2Flibvirt.git parallels: fix leaks in parallelsFindVolumes We always have to close opened dir and free 'path'. Signed-off-by: Dmitry Guryanov --- diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index 148d870d3f..0d59cce9d5 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -86,13 +86,14 @@ parallelsFindVolumes(virStoragePoolObjPtr pool) { DIR *dir; struct dirent *ent; - char *path; + char *path = NULL; + int ret = -1; if (!(dir = opendir(pool->def->target.path))) { virReportSystemError(errno, _("cannot open path '%s'"), pool->def->target.path); - goto cleanup; + return -1; } while ((ent = readdir(dir)) != NULL) { @@ -100,18 +101,21 @@ parallelsFindVolumes(virStoragePoolObjPtr pool) continue; if (!(path = virFileBuildPath(pool->def->target.path, - ent->d_name, NULL))) - goto no_memory; + ent->d_name, NULL))) { + virReportOOMError(); + goto cleanup; + } if (!parallelsStorageVolumeDefine(pool, NULL, path, false)) goto cleanup; + VIR_FREE(path); } - return 0; -no_memory: - virReportOOMError(); + ret = 0; cleanup: - return -1; + VIR_FREE(path); + closedir(dir); + return ret; }