Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

replaced newRV() with newRV_noinc in Tweak.xs to avoid leaks

  • Loading branch information...
commit 09b1143b392ec7288fabb9e9b5b4ddaf863e51bc 1 parent 4c86fb9
Stanislav Sinyagin authored June 21, 2012
22  lib/RRD/Tweak.xs
@@ -166,11 +166,11 @@ _load_file(HV *self, char *filename)
166 166
                    newSVuv(rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt), 0);
167 167
 
168 168
           /* done with this DS -- store it into ds_list array */
169  
-          av_push(ds_list, newRV((SV *) ds_params));
  169
+          av_push(ds_list, newRV_noinc((SV *) ds_params));
170 170
       }
171 171
 
172 172
       /* done with datasources -- attach ds_list as $self->{ds} */
173  
-      hv_store(self, "ds", 2, newRV((SV *) ds_list), 0);
  173
+      hv_store(self, "ds", 2, newRV_noinc((SV *) ds_list), 0);
174 174
 
175 175
 
176 176
       /* process RRA's */
@@ -326,7 +326,7 @@ _load_file(HV *self, char *filename)
326 326
                   }
327 327
 
328 328
                   hv_store(ds_cdp_prep, "history", 7,
329  
-                           newRV((SV *) history_array), 0);
  329
+                           newRV_noinc((SV *) history_array), 0);
330 330
               }
331 331
 
332 332
               break;
@@ -347,15 +347,15 @@ _load_file(HV *self, char *filename)
347 347
               }
348 348
 
349 349
               /* done with this DS CDP. store it into rra_cdp_prep array */
350  
-              av_push(rra_cdp_prep, newRV((SV *) ds_cdp_prep));
  350
+              av_push(rra_cdp_prep, newRV_noinc((SV *) ds_cdp_prep));
351 351
           }
352 352
 
353 353
           /* done with all datasources. Store rra_cdp_prep into cdp_prep_list */
354  
-          av_push(cdp_prep_list, newRV((SV *) rra_cdp_prep));
  354
+          av_push(cdp_prep_list, newRV_noinc((SV *) rra_cdp_prep));
355 355
 
356 356
 
357 357
           /* done with RRA definition, attach it to rradef_list array */
358  
-          av_push(rradef_list, newRV((SV *) rra_params));
  358
+          av_push(rradef_list, newRV_noinc((SV *) rra_params));
359 359
 
360 360
           /* extract the RRA data */
361 361
           rrd_seek(rrd_file, (rra_start + (rrd.rra_ptr[i].cur_row + 1)
@@ -376,21 +376,21 @@ _load_file(HV *self, char *filename)
376 376
                   av_push(cdp_row, newSVnv(my_cdp));
377 377
               }
378 378
 
379  
-              av_push(rra_cdp_rows, newRV((SV *) cdp_row));
  379
+              av_push(rra_cdp_rows, newRV_noinc((SV *) cdp_row));
380 380
           }
381 381
 
382 382
           /* done with this RRA. Add it to cdp_data array */
383  
-          av_push(cdp_data, newRV((SV *) rra_cdp_rows));
  383
+          av_push(cdp_data, newRV_noinc((SV *) rra_cdp_rows));
384 384
       }
385 385
 
386 386
       /* done with RRA processing -- attach rradef_list as $self->{rra} */
387  
-      hv_store(self, "rra", 3, newRV((SV *) rradef_list), 0);
  387
+      hv_store(self, "rra", 3, newRV_noinc((SV *) rradef_list), 0);
388 388
 
389 389
       /* attach cdp_prep_list as $self->{cdp_prep} */
390  
-      hv_store(self, "cdp_prep", 8, newRV((SV *) cdp_prep_list), 0);
  390
+      hv_store(self, "cdp_prep", 8, newRV_noinc((SV *) cdp_prep_list), 0);
391 391
 
392 392
       /* attach cdp_data as $self->{cdp_data} */
393  
-      hv_store(self, "cdp_data", 8, newRV((SV *) cdp_data), 0);
  393
+      hv_store(self, "cdp_data", 8, newRV_noinc((SV *) cdp_data), 0);
394 394
 
395 395
       rrd_free(&rrd);
396 396
       rrd_close(rrd_file);
53  t/20-leaktrace.skip
... ...
@@ -0,0 +1,53 @@
  1
+
  2
+use Test::More tests => 3;
  3
+use Test::LeakTrace;
  4
+
  5
+
  6
+use File::Temp qw/tmpnam/;
  7
+use RRDs;
  8
+use Data::Dumper;
  9
+
  10
+BEGIN {
  11
+  use_ok('RRD::Tweak', "use RRD::Tweak") or
  12
+    BAIL_OUT("cannot load the module");
  13
+}
  14
+
  15
+diag("Testing RRD::Tweak $RRD::Tweak::VERSION, Perl $], $^X");
  16
+
  17
+my $filename1 = tmpnam();
  18
+
  19
+# 1326585600 = Sun Jan 15 01:00:00 2012
  20
+RRDs::create($filename1, '--step', '300',
  21
+             '--start', '1326585600',
  22
+             'DS:x1:GAUGE:600:-1e10:1e15',
  23
+             'DS:x2:GAUGE:600:0.0001:U',
  24
+             'DS:x3:GAUGE:600:0.0001:U',
  25
+             'RRA:AVERAGE:0:1:20',
  26
+             'RRA:AVERAGE:0.17:6:20');
  27
+
  28
+
  29
+my $err = RRDs::error();
  30
+ok((not $err), "creating RRD file: $filename1") or
  31
+  BAIL_OUT("Cannot create RRD file: " . $err);
  32
+
  33
+leaks_cmp_ok{
  34
+    for my $x (0..3) {
  35
+        my $rrd = RRD::Tweak->new();
  36
+        $rrd->load_file($filename1);
  37
+    }
  38
+} '<', 1;
  39
+
  40
+
  41
+unlink $filename1;
  42
+
  43
+
  44
+
  45
+# Local Variables:
  46
+# mode: cperl
  47
+# indent-tabs-mode: nil
  48
+# cperl-indent-level: 4
  49
+# cperl-continued-statement-offset: 4
  50
+# cperl-continued-brace-offset: -4
  51
+# cperl-brace-offset: 0
  52
+# cperl-label-offset: -2
  53
+# End:

0 notes on commit 09b1143

Please sign in to comment.
Something went wrong with that request. Please try again.