[libvirt] [PATCH 7/7] util: use glib allocation functions

Ján Tomko jtomko at redhat.com
Mon Sep 2 14:52:47 UTC 2019


On Thu, Aug 29, 2019 at 07:02:50PM +0100, Daniel P. Berrangé wrote:
>GLib requires that any memory allocated with g_new/g_malloc/etc
>is free'd by g_free. This means mixing virAlloc with g_free,
>or g_new with virFree will violate API rules. The easy way to
>dea with this is to simply make our allocation functions wrappers

s/dea/deal/

>to the glib functions.
>
>Use of our allocation functions can be phased out gradually
>over time. When doing such conversions, the return values checks
>can be dropped at the same time.
>
>Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
>---
> src/util/viralloc.c | 29 ++++++-----------------------
> 1 file changed, 6 insertions(+), 23 deletions(-)
>

I'm afraid this is incomplete.

The obvious mismatch being VIR_STRDUP calling strdup while
VIR_FREE would call g_free now.

Same with (v)asprintf. We also use VIR_FREE to free memory
allocated by external libraries (e.g. virXMLPropString; while
there is a xmlFree function which is just an alias for free,
we never use it in libvirt code)

Maybe the safer approach would be to convert the code gradually
and explicitly use g_alloc and g_free/g_autoptr without the wrappers?

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190902/49762478/attachment-0001.sig>


More information about the libvir-list mailing list