[PATCH] domain_conf: Fix memory leak when free'ing virDomainObj

Pavel Hrdina phrdina at redhat.com
Tue Aug 10 09:51:05 UTC 2021


On Mon, Aug 09, 2021 at 03:04:35PM +0800, Luke Yue wrote:
> Free dom->deprecations when free'ing virDomainObj
> 
> Signed-off-by: Luke Yue <lukedyue at gmail.com>
> ---
>  src/conf/domain_conf.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 09da4ab952..2527cd1d70 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -3733,6 +3733,7 @@ void virDomainDefFree(virDomainDef *def)
>  static void virDomainObjDispose(void *obj)
>  {
>      virDomainObj *dom = obj;
> +    size_t i = 0;
>  
>      VIR_DEBUG("obj=%p", dom);
>      virCondDestroy(&dom->cond);
> @@ -3742,6 +3743,11 @@ static void virDomainObjDispose(void *obj)
>      if (dom->privateDataFreeFunc)
>          (dom->privateDataFreeFunc)(dom->privateData);
>  
> +    for (i = 0; i < dom->ndeprecations; i++) {
> +        g_free(dom->deprecations[i]);
> +    }
> +    g_free(dom->deprecations);
> +

Nice catch, can you add the code to separate function? For example:

virDomainObjDepracationFree()

Otherwise looks good.

Pavel

>      virDomainSnapshotObjListFree(dom->snapshots);
>      virDomainCheckpointObjListFree(dom->checkpoints);
>  }
> -- 
> 2.32.0
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210810/ef805fc8/attachment-0001.sig>


More information about the libvir-list mailing list