Fix session-lifespan memory leak when a plperl function is redefined:
authorTom Lane <[email protected]>
Sun, 29 Nov 2009 21:02:16 +0000 (21:02 +0000)
committerTom Lane <[email protected]>
Sun, 29 Nov 2009 21:02:16 +0000 (21:02 +0000)
we have to tell Perl it can release its compiled copy of the function
text.  Noted by Alexey Klyukin.

Back-patch to 8.2 --- the problem exists further back, but this patch
won't work without modification, and it's probably not worth the trouble.

src/pl/plperl/plperl.c

index d5f9d263cce4d8dc0cb7af49c41db3f373c6ac6b..1b0709897f6f468857e68c68d23ed51e25a88884 100644 (file)
@@ -1651,11 +1651,13 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
 
        if (!uptodate)
        {
+           hash_search(plperl_proc_hash, internal_proname,
+                       HASH_REMOVE, NULL);
+           if (prodesc->reference)
+               SvREFCNT_dec(prodesc->reference);
            free(prodesc->proname);
            free(prodesc);
            prodesc = NULL;
-           hash_search(plperl_proc_hash, internal_proname,
-                       HASH_REMOVE, NULL);
        }
    }