-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 06/18/2014 12:14 PM, Joe Conway wrote:
> On 06/18/2014 12:09 PM, Tom Lane wrote:
>> Joe Conway <[email protected]> writes:
>>> I think the context deletion was missed in the first place
>>> because storeRow() is the wrong place to create the context.
>>> Rather than creating the context in storeRow() and deleting it
>>> two levels up in materializeQueryResult(), I think it should
>>> be created and deleted in the interim layer,
>>> storeQueryResult(). Patch along those lines attached.
>
>> Since the storeInfo struct is longer-lived than
>> storeQueryResult(), it'd probably be better if the cleanup
>> looked like
>
>> + if (sinfo->tmpcontext != NULL) +
>> MemoryContextDelete(sinfo->tmpcontext); + sinfo->tmpcontext =
>> NULL;
>
>
> good point
If there is no further discussion, I will commit this version of the
patch back to 9.2 where this leak was introduced.
Joe
- --
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBAgAGBQJTompDAAoJEDfy90M199hlZoMP/333eXbmFvh1WCowMehKPEy1
WV3VgyZx7hBvSr/cP/HUMjXTb34hRgi5uGa79ZMyAW+U+jDxrIN4ozxp54LlgU5x
pTzD8J8VviunvWzf6stgHTe5bfcBJ9kA9oZlgHApH+JRGeySsYALI4ZBluJa1tRa
gf6ePd8Kwl4AUucbM3v7kJGxtVS5XRGKcffJnATg+OLiBUReVv9ZCjxeYasyOaRt
K2Q8ijW878UgV9HViTCsl8THelnlh7q0BpbKaSZBJG847CgmrVxfRt/l8Od8a4G/
ODoQ/fV0ZOI3h5j9oirL4/RC9HWOqchJBvBd3CK7caWLwNKVwqqEWGV3uqEO2TnA
NH3QgHb4u8WGNhoWbwL6dGWa27s2EntlWLpJRuavKxCIN2owvVBKSZ6H8d3dSlI5
AqaGnxOPvxWEB5K2w0wBynkZ9nrk4PYuIVKADu8fqyYyDsG3wGsZmI1trLNXj5sm
uE/FTbdvUjcU2uIVMMJSbPxa5JvvfR/+9rM/AF8VP5PMnSs1CyeLQXkW7nazRZOP
7zHUY6N4vwem8tVQuuXPouLu2B/eTJoXaUTm7iQvXztJDmwKxKgYCzLW/LxfvI4Q
mDIY/Arh/4RdC7kVXu6m5BEisNIbBuKtcA6f0DM+4G9i0Wtft450fgajYV4xcic9
DMPyBMwD7csz3ssF04Ox
=PJyj
-----END PGP SIGNATURE-----
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index a81853f..2e43c8f 100644
*** a/contrib/dblink/dblink.c
--- b/contrib/dblink/dblink.c
*************** storeQueryResult(storeInfo *sinfo, PGcon
*** 1076,1081 ****
--- 1076,1089 ----
if (!PQsetSingleRowMode(conn)) /* shouldn't fail */
elog(ERROR, "failed to set single-row mode for dblink query");
+ /* Create short-lived memory context for data conversions */
+ if (!sinfo->tmpcontext)
+ sinfo->tmpcontext = AllocSetContextCreate(CurrentMemoryContext,
+ "dblink temporary context",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
+
for (;;)
{
CHECK_FOR_INTERRUPTS();
*************** storeQueryResult(storeInfo *sinfo, PGcon
*** 1119,1124 ****
--- 1127,1137 ----
/* clean up GUC settings, if we changed any */
restoreLocalGucs(nestlevel);
+ /* clean up data conversion short-lived memory context */
+ if (sinfo->tmpcontext != NULL)
+ MemoryContextDelete(sinfo->tmpcontext);
+ sinfo->tmpcontext = NULL;
+
/* return last_res */
res = sinfo->last_res;
sinfo->last_res = NULL;
*************** storeRow(storeInfo *sinfo, PGresult *res
*** 1204,1218 ****
if (sinfo->cstrs)
pfree(sinfo->cstrs);
sinfo->cstrs = (char **) palloc(nfields * sizeof(char *));
-
- /* Create short-lived memory context for data conversions */
- if (!sinfo->tmpcontext)
- sinfo->tmpcontext =
- AllocSetContextCreate(CurrentMemoryContext,
- "dblink temporary context",
- ALLOCSET_DEFAULT_MINSIZE,
- ALLOCSET_DEFAULT_INITSIZE,
- ALLOCSET_DEFAULT_MAXSIZE);
}
/* Should have a single-row result if we get here */
--- 1217,1222 ----
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers