On Mon, May 17, 2021 at 06:12:56PM +0200, Michal Privoznik wrote: > The basic use case of VIR_IDENTITY_AUTORESTORE() is in > conjunction with virIdentityElevateCurrent(). What happens is > that virIdentityElevateCurrent() gets current identity (which > increases the refcounter of thread local virIdentity object) and > returns a pointer to it. Later, when the variable goes out of > scope the virIdentityRestoreHelper() is called which calls > virIdentitySetCurrent() over the old identity. But this means > that the refcounter is increased again. > > Therefore, we have to explicitly decrease the refcounter by > calling g_object_unref(). Opps, yes, i remember thinking about this and clearly forgot it again. > > Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> > --- > > I've observed this imbalance whilst running qemuxml2argvtest under > valgrind: > > ==10412== 949 (40 direct, 909 indirect) bytes in 1 blocks are definitely lost in loss record 524 of 539 > ==10412== at 0x48397EF: malloc (vg_replace_malloc.c:307) > ==10412== by 0x50806F8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.7) > ==10412== by 0x50992FD: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.6600.7) > ==10412== by 0x50999B9: g_slice_alloc0 (in /usr/lib64/libglib-2.0.so.0.6600.7) > ==10412== by 0x518D9AB: g_type_create_instance (in /usr/lib64/libgobject-2.0.so.0.6600.7) > ==10412== by 0x51739DC: g_object_new_internal (in /usr/lib64/libgobject-2.0.so.0.6600.7) > ==10412== by 0x5174F5C: g_object_new_with_properties (in /usr/lib64/libgobject-2.0.so.0.6600.7) > ==10412== by 0x5175978: g_object_new (in /usr/lib64/libgobject-2.0.so.0.6600.7) > ==10412== by 0x496C3C6: virIdentityNew (viridentity.c:407) > ==10412== by 0x496BF1A: virIdentityGetSystem (viridentity.c:318) > ==10412== by 0x117CEF: testCompareXMLToArgv (qemuxml2argvtest.c:653) > ==10412== by 0x148505: virTestRun (testutils.c:142) > > Test #315 doesn't tickle the bug, while test #316 does. > > src/util/viridentity.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|