Author: timbo
Date: Mon Jul  3 02:30:29 2006
New Revision: 6614

Modified:
   dbi/trunk/Changes
   dbi/trunk/DBI.xs

Log:
Fixed small memory leak (per interpreter/thread) thanks to Ephraim Dan.


Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes   (original)
+++ dbi/trunk/Changes   Mon Jul  3 02:30:29 2006
@@ -9,6 +9,7 @@
 XXX update DBD::File (as sub-module?) to match latest.
 
   Fixed memory leak (16 bytes per sth) thanks to Doru Theodor Petrescu.
+  Fixed small memory leak (per interpreter/thread) thanks to Ephraim Dan.
   Added $dbh->statistics_info thanks to Brandon Black.
 
 =head2 Changes in DBI 1.51 (svn rev 6475),   6th June 2006

Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs    (original)
+++ dbi/trunk/DBI.xs    Mon Jul  3 02:30:29 2006
@@ -171,7 +171,7 @@
        dPERINTERP_SV; dPERINTERP_PTR(PERINTERP_t *, PERINTERP)
 #   define INIT_PERINTERP \
        dPERINTERP;                                          \
-       Newz(0,PERINTERP,1,PERINTERP_t);                     \
+       PERINTERP = malloc_using_sv(sizeof(PERINTERP_t));    \
        sv_setiv(perinterp_sv, PTR2IV(PERINTERP))
 
 #   undef DBIS
@@ -188,6 +188,27 @@
 
 /* --- */
 
+static void *
+malloc_using_sv(STRLEN len)
+{
+    dTHX;
+    SV *sv = newSV(len);
+    void *p = SvPVX(sv);
+    memzero(p, len);
+    return p;
+}
+
+static char *
+savepv_using_sv(char *str)
+{
+    char *buf = malloc_using_sv(strlen(str));
+    strcpy(buf, str);
+    return buf;
+}
+
+
+/* --- */
+
 static void
 check_version(const char *name, int dbis_cv, int dbis_cs, int need_dbixs_cv, 
int drc_s, 
        int dbc_s, int stc_s, int fdc_s)
@@ -215,7 +236,7 @@
     dTHX;      
     INIT_PERINTERP;
 
-    Newz(dummy, DBIS, 1, dbistate_t);
+    DBIS = (struct dbistate_st*)malloc_using_sv(sizeof(struct dbistate_st));
 
     /* store version and size so we can spot DBI/DBD version mismatch  */
     DBIS->check_version = check_version;
@@ -3803,7 +3824,7 @@
            ima->minargs = (U8)SvIV(*av_fetch(av, 0, 1));
            ima->maxargs = (U8)SvIV(*av_fetch(av, 1, 1));
            svp = av_fetch(av, 2, 0);
-           ima->usage_msg  = savepv( (svp) ? SvPV(*svp,lna) : "");
+            ima->usage_msg = (svp) ? savepv_using_sv(SvPV(*svp, lna)) : "";
            ima->flags |= IMA_HAS_USAGE;
            if (trace_msg && DBIS_TRACE_LEVEL >= 11)
                sv_catpvf(trace_msg, ",\n    usage: min %d, max %d, '%s'",

Reply via email to