Re: describe objects, as in pg_depend

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: describe objects, as in pg_depend
Date: 2010-11-18 18:59:51
Message-ID: 1290106326-sup-6018@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I just noticed that this is leaking a bit of memory, because we call
getObjectDescription (which pallocs its result) and then
cstring_to_text which pallocs a copy. This is not a lot and it's not
going to live much anyway, is it worrying about? I reworked it like
this:

{
char *description = NULL;
text *tdesc;

...

description = getObjectDescription(&address);
tdesc = cstring_to_text(description);
pfree(description);

PG_RETURN_TEXT_P(tdesc);
}

I notice that ruleutils.c has a convenience function string_to_text which is
designed to avoid this problem:

static text *
string_to_text(char *str)
{
text *result;

result = cstring_to_text(str);
pfree(str);
return result;
}

So I could just make that non-static (though I'd move it to varlena.c
while at it) and use that instead.

I wonder if it's worth going through some of the other callers of
cstring_to_text and change them to use this wrapper. There are some
that are leaking some memory, though it's a tiny amount and I'm not
sure it's worth the bother. (But if so, why is ruleutils going the
extra mile?)

--
Álvaro Herrera <alvherre(at)commandprompt(dot)com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2010-11-18 19:14:52 Re: Indent authentication overloading
Previous Message Tom Lane 2010-11-18 18:56:59 Re: final patch - plpgsql: for-in-array