From: Michal Privoznik Date: Mon, 15 Feb 2021 16:19:10 +0000 (+0100) Subject: qemu: Bring if() outside from loop in virDomainFSInfoFormat() X-Git-Tag: v7.1.0-rc1~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ad1e1d89739a31927a5f4ac70898b06f03f5e27;p=thirdparty%2Flibvirt.git qemu: Bring if() outside from loop in virDomainFSInfoFormat() After previous commit, the freeing of @info_ret inside of virDomainFSInfoFormat() looks like this: for () { if (info_ret) virDomainFSInfoFree(info_ret[i]); } It is needless to compare @info_ret against NULL in each iteration. We can switch the order and do the comparison first followed by the loop. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 71c823abd0..d30cf75b73 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18977,13 +18977,14 @@ virDomainFSInfoFormat(qemuAgentFSInfoPtr *agentinfo, ret = nagentinfo; cleanup: - for (i = 0; i < nagentinfo; i++) { - /* if there was an error, free any memory we've allocated for the - * return value */ - if (info_ret) + if (info_ret) { + for (i = 0; i < nagentinfo; i++) { + /* if there was an error, free any memory we've allocated for the + * return value */ virDomainFSInfoFree(info_ret[i]); + } + g_free(info_ret); } - g_free(info_ret); return ret; }