Re: describe objects, as in pg_depend - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: describe objects, as in pg_depend
Date
Msg-id 1290106326-sup-6018@alvh.no-ip.org
Whole thread Raw
In response to Re: describe objects, as in pg_depend  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: describe objects, as in pg_depend
List 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@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: final patch - plpgsql: for-in-array
Next
From: Greg Stark
Date:
Subject: Re: Indent authentication overloading