develooper Front page | perl.perl5.porters | Postings from April 2006

[PATCH] Potential (?) memory leak in Storable.xs (Coverity)

Thread Next
From:
bah
Date:
April 15, 2006 16:21
Subject:
[PATCH] Potential (?) memory leak in Storable.xs (Coverity)
Message ID:
1564.38.96.138.153.1145123690.squirrel@mail.longitude.com
If av_store() fails while restoring an object (I suppose an inordinately
long class name might trigger this) the memory allocated for the classname
was lost.  I don't trust my mailer so I also attached the patch.

Ben

--- ext/Storable/Storable.xs.orig	2006-04-15 11:43:31.000000000 -0400
+++ ext/Storable/Storable.xs	2006-04-15 11:41:58.000000000 -0400
@@ -3985,8 +3985,11 @@

 	TRACEME(("new class name \"%s\" will bear ID = %d", classname,
cxt->classnum));

-	if (!av_store(cxt->aclass, cxt->classnum++, newSVpvn(classname, len)))
+	if (!av_store(cxt->aclass, cxt->classnum++, newSVpvn(classname, len))) {
+		if (classname != buf)
+			Safefree(classname);
 		return (SV *) 0;
+	}

 	/*
 	 * Retrieve object and bless it.
@@ -4164,8 +4167,11 @@
 		 * Record new classname.
 		 */

-		if (!av_store(cxt->aclass, cxt->classnum++, newSVpvn(classname, len)))
+		if (!av_store(cxt->aclass, cxt->classnum++, newSVpvn(classname, len))) {
+			if (classname != buf)
+				Safefree(classname);
 			return (SV *) 0;
+		}
 	}

 	TRACEME(("class name: %s", classname));

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About