Re: describe objects, as in pg_depend

Alvaro Herrera <alvherre@commandprompt.com>

From: Alvaro Herrera <alvherre@commandprompt.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2010-11-18T18:59:51Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. has_table_privilege spawns scions has_database_privilege, has_function_privilege,

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