diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index a81853f..46c4a51 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,1136 ----
  	/* 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);
+ 
  	/* 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 */
--- 1216,1221 ----
