[perl-Text-CSV_XS/f16] Fix memory leak in xsParse_all

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

 



commit f0896ef08a095dd0445fb9687734cb69ef52257e
Author: Petr Písař <ppisar@xxxxxxxxxx>
Date:   Tue Dec 4 11:35:55 2012 +0100

    Fix memory leak in xsParse_all

 ...cing-double-references-on-per-line-AVs-in.patch |   46 ++++++++++++++++++++
 ...3-eliminate-rav_free-it-s-not-longer-used.patch |   30 +++++++++++++
 perl-Text-CSV_XS.spec                              |    7 +++
 3 files changed, 83 insertions(+), 0 deletions(-)
---
diff --git a/Text-CSV_XS-0.93-avoid-producing-double-references-on-per-line-AVs-in.patch b/Text-CSV_XS-0.93-avoid-producing-double-references-on-per-line-AVs-in.patch
new file mode 100644
index 0000000..78d8df3
--- /dev/null
+++ b/Text-CSV_XS-0.93-avoid-producing-double-references-on-per-line-AVs-in.patch
@@ -0,0 +1,46 @@
+From b7623f803c1d78b565d4f7aa9b2850a09b256df5 Mon Sep 17 00:00:00 2001
+From: Tony Cook <tony@xxxxxxxxxxxxxxxx>
+Date: Mon, 3 Dec 2012 20:36:14 +1100
+Subject: [PATCH 1/2] avoid producing double references on per-line AVs in
+ xsParse_all()
+
+The code used newRV(), which is an alias for newRV_inc(), hence the
+line AVs each had a reference count of 2 when they were returned.
+
+rav_free() handled this by releasing both the RV and the underlying
+AV, but this is unnecessary when the AVs have the correct reference
+count.
+---
+ CSV_XS.xs |    6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/CSV_XS.xs b/CSV_XS.xs
+index 553f7fc..09fcdef 100644
+--- a/CSV_XS.xs
++++ b/CSV_XS.xs
+@@ -1533,11 +1533,11 @@ static SV *cx_xsParse_all (pTHX_ SV *self, HV *hv, SV *io, SV *off, SV *len)
+ 	    }
+ 
+ 	if (n++ >= tail) {
+-	    rav_free (av_shift (avr));
++	    SvREFCNT_dec(av_shift (avr));
+ 	    n--;
+ 	    }
+ 
+-	av_push (avr, newRV ((SV *)row));
++	av_push (avr, newRV_noinc ((SV *)row));
+ 
+ 	if (n >= length && skip >= 0)
+ 	    break; /* We have enough */
+@@ -1545,7 +1545,7 @@ static SV *cx_xsParse_all (pTHX_ SV *self, HV *hv, SV *io, SV *off, SV *len)
+ 	row = newAV ();
+ 	}
+     while (n > length) {
+-	rav_free (av_pop (avr));
++	SvREFCNT_dec(av_pop (avr));
+ 	n--;
+ 	}
+ 
+-- 
+1.7.10.4
+
diff --git a/Text-CSV_XS-0.93-eliminate-rav_free-it-s-not-longer-used.patch b/Text-CSV_XS-0.93-eliminate-rav_free-it-s-not-longer-used.patch
new file mode 100644
index 0000000..9086fa7
--- /dev/null
+++ b/Text-CSV_XS-0.93-eliminate-rav_free-it-s-not-longer-used.patch
@@ -0,0 +1,30 @@
+From 6fab5ebee68ee16fb5e3ad926fb7cda0180dae0c Mon Sep 17 00:00:00 2001
+From: Tony Cook <tony@xxxxxxxxxxxxxxxx>
+Date: Mon, 3 Dec 2012 20:40:05 +1100
+Subject: [PATCH 2/2] eliminate rav_free(), it's not longer used
+
+---
+ CSV_XS.xs |    7 -------
+ 1 file changed, 7 deletions(-)
+
+diff --git a/CSV_XS.xs b/CSV_XS.xs
+index 09fcdef..b0fed4a 100644
+--- a/CSV_XS.xs
++++ b/CSV_XS.xs
+@@ -1497,13 +1497,6 @@ static void cx_av_free (pTHX_ AV *av)
+     sv_free ((SV *)av);
+     } /* av_free */
+ 
+-#define rav_free(rv)	cx_rav_free (aTHX_ rv)
+-static void cx_rav_free (pTHX_ SV *rv)
+-{
+-    av_free ((AV *)SvRV (rv));
+-    sv_free (rv);
+-    } /* rav_free */
+-
+ #define xsParse_all(self,hv,io,off,len)		cx_xsParse_all (aTHX_ self, hv, io, off, len)
+ static SV *cx_xsParse_all (pTHX_ SV *self, HV *hv, SV *io, SV *off, SV *len)
+ {
+-- 
+1.7.10.4
+
diff --git a/perl-Text-CSV_XS.spec b/perl-Text-CSV_XS.spec
index 2d83429..68f3f45 100644
--- a/perl-Text-CSV_XS.spec
+++ b/perl-Text-CSV_XS.spec
@@ -8,6 +8,10 @@ URL:            http://search.cpan.org/dist/Text-CSV_XS/
 Source0:        http://www.cpan.org/authors/id/H/HM/HMBRAND/Text-CSV_XS-%{version}.tgz
 # In upstream 0.94, CPAN RT #81469
 Patch0:         Text-CSV_XS-88-Fix-sv_cache-init-global-buffer-overflow-Reini-Urban.patch
+# In upstream 0.94, CPAN RT #81539
+Patch1:         Text-CSV_XS-0.93-avoid-producing-double-references-on-per-line-AVs-in.patch
+# In upstream 0.94, CPAN RT #81539
+Patch2:         Text-CSV_XS-0.93-eliminate-rav_free-it-s-not-longer-used.patch
 
 BuildRequires:  perl(Test::Pod)
 BuildRequires:  perl(Test::Pod::Coverage)
@@ -29,6 +33,8 @@ fields into a CSV string and parse a CSV string into fields.
 %prep
 %setup -q -n Text-CSV_XS-%{version}
 %patch0 -p1
+%patch1 -p1
+%patch2 -p1
 iconv -f latin1 -t utf8 ChangeLog > ChangeLog.utf8 && mv ChangeLog.utf8 ChangeLog
 chmod -c a-x examples/*
 # Upstream does this on purpose (2011-03-23):
@@ -67,6 +73,7 @@ make test
 %changelog
 * Tue Dec 04 2012 Petr Pisar <ppisar@xxxxxxxxxx> - 0.82-3
 - Fix sc_cache initialization (CPAN RT #81469)
+- Fix memory leak in xsParse_all (CPAN RT #81539)
 
 * Mon Jun 20 2011 Marcela Mašláňová <mmaslano@xxxxxxxxxx> - 0.82-2
 - Perl mass rebuild
--
Fedora Extras Perl SIG
http://www.fedoraproject.org/wiki/Extras/SIGs/Perl
perl-devel mailing list
perl-devel@xxxxxxxxxxxxxxxxxxxxxxx
https://admin.fedoraproject.org/mailman/listinfo/perl-devel



[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Legacy Announce]     [Fedora PHP Devel]     [Kernel Devel]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Big List of Linux Books]     [Gimp]     [Yosemite Information]
  Powered by Linux