On 12/20/19 3:34 PM, Cole Robinson wrote:
On 12/19/19 4:09 PM, Daniel Henrique Barboza wrote:
Change all feasible strings and scalar pointers to use g_autofree.

Signed-off-by: Daniel Henrique Barboza <danielhb...@gmail.com>
---
  src/qemu/qemu_process.c | 97 +++++++++++++++--------------------------
  1 file changed, 34 insertions(+), 63 deletions(-)
[...]>>

Last one looks suspicious, either it's fixing a memory leak or something
is wrong! It's a bit of both. Later code is:


     template = g_strdup_printf("%s/qmp-XXXXXX", proc->libDir);

     if (!(proc->uniqDir = g_mkdtemp(template))) {

         virReportSystemError(errno,

                              _("Failed to create unique directory with "

                                "template '%s' for probing QEMU"),

                              template);

         return -1;

     }

g_mkdtemp actually alters and returns the passed in string, it doesn't
return new memory. So if g_mkdtemp succeeds, we are transfering
ownership to proc->uniqDir. There's a bug though that template isn't
free'd if g_mkdtemp fails.

So if you convert to g_autofree, after g_mkdtemp succeeds, you need to
set 'template = NULL';

Thanks. I got a weird feeling about this change (this code wasn't present in
the previous version) because I thought strange that no one put a VIR_FREE()
in a string returned by g_strdup_printf(), which I know for a fact that
put stuff in the heap.


DHB


- Cole


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to