From 8a80df95ac1cdd481bbabbd6fcda666bedc9b1ed Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 20 Jan 2022 11:34:46 +0100 Subject: [PATCH] virStoragePoolObjLoadAllConfigs: Use automatic memory clearing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor the inner loop to automatically free temporary variables and remove unreachable error paths. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/virstorageobj.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 815ada8584..4081e12823 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -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;