Re: [BUGS] BUG #9223: plperlu result memory leak

From: Sergey Burladyan <eshkinkot(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [BUGS] BUG #9223: plperlu result memory leak
Date: 2014-02-25 13:56:01
Message-ID: 87ppmbmh3i.fsf@seb.koffice.internal
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hello, All!

eshkinkot(at)gmail(dot)com writes:

> create function perl_test(IN data text, OUT v1 text, OUT v2 integer, OUT v3
> integer, OUT v4 json, OUT v5 json)
> returns record as
> $BODY$
>
> use strict;
> use warnings;
>
> my $res->{'v1'} = 'content';
>
> return $res;
>
> $BODY$
> language plperlu volatile strict;

> test case:
> select count(perl_test('')) from generate_series(1, 1000000);

It looks like I found the problem, Perl use reference count and something that
is called "Mortal" for memory management. As I understand it, mortal is free
after FREETMPS. Plperl call FREETMPS in plperl_call_perl_func() but after it,
plperl ask perl interpreter again for new mortal SV variables, for example, in
hek2cstr from plperl_sv_to_datum, and this new SV is newer freed.

I experiment with this patch, and it fix memory leak in my case, but patch
is incomplete. It does not free on error and fix only plperl_func_handler,
plperl_trigger_handler and may be plperl_inline_handler must be also fixed.

Patch for REL9_2_STABLE.

without patch:
PID VSZ RSS
2503 74112 7740
2503 152928 86860
2503 232208 165836
2503 310732 244508
2503 389264 323032

with patch:
PID VSZ RSS
4322 74112 7740
4322 74380 8340
4322 74380 8340
4322 74380 8340
4322 74380 8340

Attachment Content-Type Size
0001-WIP-plperl-memory-leak.patch text/x-diff 524 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Brian Crowell 2014-02-25 15:07:46 Re: BUG #9337: SSPI/GSSAPI with mismatched user names
Previous Message Patrick Wege 2014-02-25 13:13:31 Re: BUG #9308: The application failed to initialize properly

Browse pgsql-hackers by date

  From Date Subject
Next Message Kohei KaiGai 2014-02-25 14:24:05 Re: Custom Scan APIs (Re: Custom Plan node)
Previous Message Andreas 'ads' Scherbaum 2014-02-25 13:28:52 Re: GSoC 2014 - mentors, students and admins