[libvirt] [PATCH] util: Don't leak linksrc in vircgroup

Martin Kletzander posted 1 patch 6 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/281039d9a6c60823d24bf06e3f3d54702842fe1d.1499933042.git.mkletzan@redhat.com
src/util/vircgroup.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
[libvirt] [PATCH] util: Don't leak linksrc in vircgroup
Posted by Martin Kletzander 6 years, 9 months ago
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/util/vircgroup.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index a53908fc9246..2912fc9be539 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -382,6 +382,8 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
     FILE *mounts = NULL;
     struct mntent entry;
     char buf[CGROUP_MAX_VAL];
+    char *linksrc = NULL;
+    int ret = -1;
 
     mounts = fopen(path, "r");
     if (mounts == NULL) {
@@ -409,7 +411,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
                 }
 
                 if (typelen == len && STREQLEN(typestr, tmp, len)) {
-                    char *linksrc;
                     struct stat sb;
                     char *tmp2;
 
@@ -423,35 +424,35 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
                     VIR_FREE(controller->mountPoint);
                     VIR_FREE(controller->linkPoint);
                     if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0)
-                        goto error;
+                        goto cleanup;
 
                     tmp2 = strrchr(entry.mnt_dir, '/');
                     if (!tmp2) {
                         virReportError(VIR_ERR_INTERNAL_ERROR,
                                        _("Missing '/' separator in cgroup mount '%s'"),
                                        entry.mnt_dir);
-                        goto error;
+                        goto cleanup;
                     }
 
                     /* If it is a co-mount it has a filename like "cpu,cpuacct"
                      * and we must identify the symlink path */
                     if (checkLinks && strchr(tmp2 + 1, ',')) {
                         *tmp2 = '\0';
+                        VIR_FREE(linksrc);
                         if (virAsprintf(&linksrc, "%s/%s",
                                         entry.mnt_dir, typestr) < 0)
-                            goto error;
+                            goto cleanup;
                         *tmp2 = '/';
 
                         if (lstat(linksrc, &sb) < 0) {
                             if (errno == ENOENT) {
                                 VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
                                          typestr, entry.mnt_dir, linksrc);
-                                VIR_FREE(linksrc);
                             } else {
                                 virReportSystemError(errno,
                                                      _("Cannot stat %s"),
                                                      linksrc);
-                                goto error;
+                                goto cleanup;
                             }
                         } else {
                             if (!S_ISLNK(sb.st_mode)) {
@@ -459,6 +460,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
                                          linksrc, typestr);
                             } else {
                                 controller->linkPoint = linksrc;
+                                linksrc = NULL;
                             }
                         }
                     }
@@ -468,13 +470,11 @@ virCgroupDetectMountsFromFile(virCgroupPtr group,
         }
     }
 
+    ret = 0;
+ cleanup:
+    VIR_FREE(linksrc);
     VIR_FORCE_FCLOSE(mounts);
-
-    return 0;
-
- error:
-    VIR_FORCE_FCLOSE(mounts);
-    return -1;
+    return ret;
 }
 
 static int
-- 
2.13.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: Don't leak linksrc in vircgroup
Posted by Michal Privoznik 6 years, 9 months ago
On 07/13/2017 10:04 AM, Martin Kletzander wrote:
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> ---
>  src/util/vircgroup.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list