]> xenbits.xensource.com Git - libvirt.git/commitdiff
virStoragePoolObjLoadAllConfigs: Use automatic memory clearing
authorPeter Krempa <pkrempa@redhat.com>
Thu, 20 Jan 2022 10:34:46 +0000 (11:34 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 20 Jan 2022 13:23:56 +0000 (14:23 +0100)
Refactor the inner loop to automatically free temporary variables and
remove unreachable error paths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/virstorageobj.c

index 815ada8584e459755c5b19d87c9772859068061c..4081e128239d5ecc72f0324d0bbd103923209841 100644 (file)
@@ -1736,27 +1736,15 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjList *pools,
         return rc;
 
     while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
-        char *path;
-        char *autostartLink;
+        g_autofree char *path = virFileBuildPath(configDir, entry->d_name, NULL);
+        g_autofree char *autostartLink = virFileBuildPath(autostartDir, entry->d_name, NULL);
         virStoragePoolObj *obj;
 
         if (!virStringHasSuffix(entry->d_name, ".xml"))
             continue;
 
-        if (!(path = virFileBuildPath(configDir, entry->d_name, NULL)))
-            continue;
-
-        if (!(autostartLink = virFileBuildPath(autostartDir, entry->d_name,
-                                               NULL))) {
-            VIR_FREE(path);
-            continue;
-        }
-
         obj = virStoragePoolObjLoad(pools, entry->d_name, path, autostartLink);
         virStoragePoolObjEndAPI(&obj);
-
-        VIR_FREE(path);
-        VIR_FREE(autostartLink);
     }
 
     return ret;