Re: [PATCH v2] openvz_conf: Use g_autofree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/14/24 21:22, Rayhan Faizel wrote:
> Signed-off-by: Rayhan Faizel <rayhan.faizel@xxxxxxxxx>
> ---
>  src/openvz/openvz_conf.c | 60 ++++++++++++----------------------------
>  1 file changed, 17 insertions(+), 43 deletions(-)

Reviewed-by: Michal Privoznik <mprivozn@xxxxxxxxxx>

and merged. Congratulations on your first libvirt contribution!

BTW: even after this patch there are some more opportunities for
automatic cleanup. They may require slight code rework though. For
instance, in openvzReadNetworkConf() the 'net' variable is declared for
the whole function even though it's really used inside a for() loop. We
can do two things:

1) decrease scope of the variable, and
2) declare it as g_autoptr(virDomainNetDef) net = NULL;

These both steps guarantee that whenever controls jumps out of the loop,
then virDomainNetDefFree(net) will be called. And to avoid freeing
definition that was just appended to def->nets,
VIR_APPEND_ELEMENT_COPY() needs to be changed to VIR_APPEND_ELEMENT()
which upon successful return set net=NULL (thus rendering
virDomainNetDefFree() to NOP).

Simirarly, 'fs' in openvzReadFSConf() can use the same treatement. But
here you may need to declare what free function corresponds to
virDomainFSDef. Take a look at src/conf/domain_conf.h for inspiration.

Finally, some labels are/will be onelines containing nothing but a
return statement. We tend to drop these and replace 'goto $LABEL' with
those return statements for easier reading of the code.

Michal
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux