Memory leak fix, by Jarkko
Rafael Garcia-Suarez [Thu, 19 Oct 2006 12:08:24 +0000 (12:08 +0000)]
p4raw-id: //depot/perl@29050

perlio.c

index 703085b..6434a9b 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -2397,6 +2397,27 @@ PerlIO_cleanup(pTHX)
        PerlIO_list_free(aTHX_ PL_def_layerlist);
        PL_def_layerlist = NULL;
     }
+#ifdef USE_THREADS
+    MUTEX_UNLOCK(&PerlIO_mutex);
+#endif
+    if (PL_perlio_fd_refcnt_size /* Assuming initial size of zero. */
+        && PL_perlio_fd_refcnt) {
+#ifdef PERL_TRACK_MEMPOOL
+        Malloc_t ptr = (Malloc_t)((char*)PL_perlio_fd_refcnt-sTHX);
+        struct perl_memory_debug_header *const header
+            = (struct perl_memory_debug_header *)ptr;
+        /* Only the thread that allocated us can free us. */
+        if (header->interpreter == aTHX)
+#endif
+           {
+               Safefree(PL_perlio_fd_refcnt);
+               PL_perlio_fd_refcnt = NULL;
+               PL_perlio_fd_refcnt_size = 0;
+           }
+    }
+#ifdef USE_THREADS
+    MUTEX_UNLOCK(&PerlIO_mutex);
+#endif
 }