[libvirt-perl][PATCH 3/3] Substitute Safefree with virTypedParamsFree

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

 



When working with typed params calling pure free() over an array
of params is not enough. Some items in the array may be type of
string in which case they have a pointer to an allocated memory
too. Therefore we should use virTypedParamsFree() which does all
the necessary.

Moreover, some methods (set_interface_parameters() and
set_block_iotune()) were missing any free at all.

==16768== 1 bytes in 1 blocks are definitely lost in loss record 2 of 7,378
==16768==    at 0x4C29F80: malloc (vg_replace_malloc.c:296)
==16768==    by 0x52603B9: strdup (strdup.c:42)
==16768==    by 0x66222E4: virStrdup (in /usr/lib64/libvirt.so.0.2000.0)
==16768==    by 0x662B92A: virTypedParamsDeserialize (in /usr/lib64/libvirt.so.0.2000.0)
==16768==    by 0x671D7F2: remoteDomainGetNumaParameters (in /usr/lib64/libvirt.so.0.2000.0)
==16768==    by 0x66CA1BE: virDomainGetNumaParameters (in /usr/lib64/libvirt.so.0.2000.0)
==16768==    by 0x630CF74: XS_Sys__Virt__Domain_get_numa_parameters (Virt.xs:4224)
==16768==    by 0x4EF920A: Perl_pp_entersub (in /usr/lib64/libperl.so.5.20.2)
==16768==    by 0x4EF1A42: Perl_runops_standard (in /usr/lib64/libperl.so.5.20.2)
==16768==    by 0x4E8BE58: perl_run (in /usr/lib64/libperl.so.5.20.2)
==16768==    by 0x400D9A: main (in /usr/bin/perl)

==16768== 672 bytes in 1 blocks are definitely lost in loss record 6,993 of 7,378
==16768==    at 0x4C29F80: malloc (vg_replace_malloc.c:296)
==16768==    by 0x4ED6984: Perl_safesysmalloc (in /usr/lib64/libperl.so.5.20.2)
==16768==    by 0x63164DF: XS_Sys__Virt__Domain_set_interface_parameters (Virt.xs:5024)
==16768==    by 0x4EF920A: Perl_pp_entersub (in /usr/lib64/libperl.so.5.20.2)
==16768==    by 0x4EF1A42: Perl_runops_standard (in /usr/lib64/libperl.so.5.20.2)
==16768==    by 0x4E8BE58: perl_run (in /usr/lib64/libperl.so.5.20.2)
==16768==    by 0x400D9A: main (in /usr/bin/perl)

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 Virt.xs | 90 +++++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 46 insertions(+), 44 deletions(-)

diff --git a/Virt.xs b/Virt.xs
index cf4e5bc..3b59f8a 100644
--- a/Virt.xs
+++ b/Virt.xs
@@ -2246,12 +2246,12 @@ get_node_memory_parameters(conn, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virNodeGetMemoryParameters(conn, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -2272,7 +2272,7 @@ set_node_memory_parameters(conn, newparams, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virNodeGetMemoryParameters(conn, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
@@ -2280,7 +2280,7 @@ set_node_memory_parameters(conn, newparams, flags=0)
 
       if (virNodeSetMemoryParameters(conn, params, nparams, flags) < 0)
           _croak_error();
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 
@@ -3924,13 +3924,13 @@ get_job_stats(dom, flags=0)
       SV *typeSv;
     PPCODE:
       if (virDomainGetJobStats(dom, &type, &params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       typeSv = newSViv(type);
       paramsHv = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
       EXTEND(SP, 2);
       PUSHs(newRV_noinc((SV*)typeSv));
@@ -4038,11 +4038,11 @@ block_copy(dom, path, destxml, newparams, flags=0)
       nparams = vir_typed_param_from_hv(newparams, params, nparams);
 
       if (virDomainBlockCopy(dom, path, destxml, params, nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 void
@@ -4103,17 +4103,17 @@ get_scheduler_parameters(dom, flags=0)
       Newx(params, nparams, virTypedParameter);
       if (flags) {
           if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, flags) < 0) {
-              Safefree(params);
+              virTypedParamsFree(params, nparams);
               _croak_error();
           }
       } else {
           if (virDomainGetSchedulerParameters(dom, params, &nparams) < 0) {
-              Safefree(params);
+              virTypedParamsFree(params, nparams);
               _croak_error();
           }
       }
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -4135,12 +4135,12 @@ set_scheduler_parameters(dom, newparams, flags=0)
       Newx(params, nparams, virTypedParameter);
       if (flags) {
           if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, flags) < 0) {
-              Safefree(params);
+              virTypedParamsFree(params, nparams);
               _croak_error();
           }
       } else {
           if (virDomainGetSchedulerParameters(dom, params, &nparams) < 0) {
-              Safefree(params);
+              virTypedParamsFree(params, nparams);
               _croak_error();
           }
       }
@@ -4152,7 +4152,7 @@ set_scheduler_parameters(dom, newparams, flags=0)
           if (virDomainSetSchedulerParameters(dom, params, nparams) < 0)
               _croak_error();
       }
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 HV *
@@ -4170,12 +4170,12 @@ get_memory_parameters(dom, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virDomainGetMemoryParameters(dom, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -4196,7 +4196,7 @@ set_memory_parameters(dom, newparams, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virDomainGetMemoryParameters(dom, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
@@ -4204,7 +4204,7 @@ set_memory_parameters(dom, newparams, flags=0)
 
       if (virDomainSetMemoryParameters(dom, params, nparams, flags) < 0)
           _croak_error();
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 HV *
@@ -4222,12 +4222,12 @@ get_numa_parameters(dom, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virDomainGetNumaParameters(dom, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -4248,7 +4248,7 @@ set_numa_parameters(dom, newparams, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virDomainGetNumaParameters(dom, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
@@ -4256,7 +4256,7 @@ set_numa_parameters(dom, newparams, flags=0)
 
       if (virDomainSetNumaParameters(dom, params, nparams, flags) < 0)
           _croak_error();
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 HV *
@@ -4274,12 +4274,12 @@ get_blkio_parameters(dom, flags=0)
       Newx(params, nparams, virBlkioParameter);
 
       if (virDomainGetBlkioParameters(dom, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -4300,7 +4300,7 @@ set_blkio_parameters(dom, newparams, flags=0)
       Newx(params, nparams, virBlkioParameter);
 
       if (virDomainGetBlkioParameters(dom, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
@@ -4309,7 +4309,7 @@ set_blkio_parameters(dom, newparams, flags=0)
       if (virDomainSetBlkioParameters(dom, params, nparams,
                                       flags) < 0)
           _croak_error();
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 HV *
@@ -4321,12 +4321,12 @@ get_perf_events(dom, flags=0)
       int nparams = 0;
     CODE:
       if (virDomainGetPerfEvents(dom, &params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -4341,7 +4341,7 @@ set_perf_events(dom, newparams, flags=0)
       int nparams = 0;
     PPCODE:
       if (virDomainGetPerfEvents(dom, &params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
@@ -4349,7 +4349,7 @@ set_perf_events(dom, newparams, flags=0)
 
       if (virDomainSetPerfEvents(dom, params, nparams, flags) < 0)
           _croak_error();
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 unsigned long
@@ -4719,10 +4719,10 @@ _migrate(dom, destcon, newparams, flags=0)
       * if it is possible todo so
       */
      if ((RETVAL = virDomainMigrate3(dom, destcon, params, nparams, flags)) == NULL) {
-         Safefree(params);
+         virTypedParamsFree(params, nparams);
          _croak_error();
      }
-     Safefree(params);
+     virTypedParamsFree(params, nparams);
  OUTPUT:
      RETVAL
 
@@ -4810,10 +4810,10 @@ _migrate_to_uri(dom, desturi, newparams, flags=0)
       * if it is possible todo so
       */
      if (virDomainMigrateToURI3(dom, desturi, params, nparams, flags) < 0) {
-         Safefree(params);
+         virTypedParamsFree(params, nparams);
          _croak_error();
      }
-     Safefree(params);
+     virTypedParamsFree(params, nparams);
 
 
 void
@@ -4947,12 +4947,12 @@ get_block_iotune(dom, disk, flags=0)
 
       Newx(params, nparams, virTypedParameter);
       if (virDomainGetBlockIoTune(dom, disk, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -4973,13 +4973,14 @@ set_block_iotune(dom, disk, newparams, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virDomainGetBlockIoTune(dom, disk, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       nparams = vir_typed_param_from_hv(newparams, params, nparams);
       if (virDomainSetBlockIoTune(dom, disk, params, nparams, flags) < 0)
           _croak_error();
+      virTypedParamsFree(params, nparams);
 
 
 HV *
@@ -4998,12 +4999,12 @@ get_interface_parameters(dom, intf, flags=0)
 
       Newx(params, nparams, virTypedParameter);
       if (virDomainGetInterfaceParameters(dom, intf, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       RETVAL = vir_typed_param_to_hv(params, nparams);
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
   OUTPUT:
       RETVAL
 
@@ -5024,13 +5025,14 @@ set_interface_parameters(dom, intf, newparams, flags=0)
       Newx(params, nparams, virTypedParameter);
 
       if (virDomainGetInterfaceParameters(dom, intf, params, &nparams, flags) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
       nparams = vir_typed_param_from_hv(newparams, params, nparams);
       if (virDomainSetInterfaceParameters(dom, intf, params, nparams, flags) < 0)
           _croak_error();
+      virTypedParamsFree(params, nparams);
 
 
 HV *
@@ -5066,7 +5068,7 @@ block_stats(dom, path, flags=0)
           Newx(params, nparams, virTypedParameter);
 
           if (virDomainBlockStatsFlags(dom, path, params, &nparams, flags) < 0) {
-              Safefree(params);
+              virTypedParamsFree(params, nparams);
               _croak_error();
           }
 
@@ -5086,7 +5088,7 @@ block_stats(dom, path, flags=0)
                   (void)hv_store(RETVAL, field, strlen(field), val, 0);
               }
           }
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
       }
   OUTPUT:
       RETVAL
@@ -5312,7 +5314,7 @@ get_cpu_stats(dom, start_cpu, ncpus, flags=0)
 
       Newx(params, ncpus * nparams, virTypedParameter);
       if ((ret = virDomainGetCPUStats(dom, params, nparams, start_cpu, ncpus, flags)) < 0) {
-          Safefree(params);
+          virTypedParamsFree(params, nparams);
           _croak_error();
       }
 
@@ -5322,7 +5324,7 @@ get_cpu_stats(dom, start_cpu, ncpus, flags=0)
           PUSHs(newRV_noinc((SV *)rec));
       }
 
-      Safefree(params);
+      virTypedParamsFree(params, nparams);
 
 
 void
-- 
2.8.4

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



[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]