Commit 41b45576 authored by Tom Lane's avatar Tom Lane

Remove useless pfree()s at the ends of various ValuePerCall SRFs.

We don't need to manually clean up allocations in a SRF's
multi_call_memory_ctx, because the SRF_RETURN_DONE infrastructure
takes care of that (and also ensures that it will happen even if the
function never gets a final call, which simple manual cleanup cannot
do).

Hence, the code removed by this patch is a waste of code and cycles.
Worse, it gives the impression that cleaning up manually is a thing,
which can lead to more serious errors such as those fixed in
commits 085b6b66 and b4570d33.  So we should get rid of it.

These are not quite actual bugs though, so I couldn't muster the
enthusiasm to back-patch.  Fix in HEAD only.

Justin Pryzby

Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com
parent b4570d33
...@@ -502,12 +502,8 @@ bt_page_items(PG_FUNCTION_ARGS) ...@@ -502,12 +502,8 @@ bt_page_items(PG_FUNCTION_ARGS)
uargs->offset++; uargs->offset++;
SRF_RETURN_NEXT(fctx, result); SRF_RETURN_NEXT(fctx, result);
} }
else
{
pfree(uargs->page);
pfree(uargs);
SRF_RETURN_DONE(fctx); SRF_RETURN_DONE(fctx);
}
} }
/*------------------------------------------------------- /*-------------------------------------------------------
...@@ -590,11 +586,8 @@ bt_page_items_bytea(PG_FUNCTION_ARGS) ...@@ -590,11 +586,8 @@ bt_page_items_bytea(PG_FUNCTION_ARGS)
uargs->offset++; uargs->offset++;
SRF_RETURN_NEXT(fctx, result); SRF_RETURN_NEXT(fctx, result);
} }
else
{
pfree(uargs);
SRF_RETURN_DONE(fctx); SRF_RETURN_DONE(fctx);
}
} }
/* Number of output arguments (columns) for bt_metap() */ /* Number of output arguments (columns) for bt_metap() */
......
...@@ -260,6 +260,6 @@ gin_leafpage_items(PG_FUNCTION_ARGS) ...@@ -260,6 +260,6 @@ gin_leafpage_items(PG_FUNCTION_ARGS)
SRF_RETURN_NEXT(fctx, result); SRF_RETURN_NEXT(fctx, result);
} }
else
SRF_RETURN_DONE(fctx); SRF_RETURN_DONE(fctx);
} }
...@@ -374,11 +374,8 @@ hash_page_items(PG_FUNCTION_ARGS) ...@@ -374,11 +374,8 @@ hash_page_items(PG_FUNCTION_ARGS)
SRF_RETURN_NEXT(fctx, result); SRF_RETURN_NEXT(fctx, result);
} }
else
{
pfree(uargs);
SRF_RETURN_DONE(fctx); SRF_RETURN_DONE(fctx);
}
} }
/* ------------------------------------------------ /* ------------------------------------------------
......
...@@ -3388,9 +3388,5 @@ pg_get_multixact_members(PG_FUNCTION_ARGS) ...@@ -3388,9 +3388,5 @@ pg_get_multixact_members(PG_FUNCTION_ARGS)
SRF_RETURN_NEXT(funccxt, HeapTupleGetDatum(tuple)); SRF_RETURN_NEXT(funccxt, HeapTupleGetDatum(tuple));
} }
if (multi->nmembers > 0)
pfree(multi->members);
pfree(multi);
SRF_RETURN_DONE(funccxt); SRF_RETURN_DONE(funccxt);
} }
...@@ -104,9 +104,6 @@ tt_process_call(FuncCallContext *funcctx) ...@@ -104,9 +104,6 @@ tt_process_call(FuncCallContext *funcctx)
st->cur++; st->cur++;
return result; return result;
} }
if (st->list)
pfree(st->list);
pfree(st);
return (Datum) 0; return (Datum) 0;
} }
...@@ -245,12 +242,6 @@ prs_process_call(FuncCallContext *funcctx) ...@@ -245,12 +242,6 @@ prs_process_call(FuncCallContext *funcctx)
st->cur++; st->cur++;
return result; return result;
} }
else
{
if (st->list)
pfree(st->list);
pfree(st);
}
return (Datum) 0; return (Datum) 0;
} }
......
...@@ -535,7 +535,6 @@ jsonb_object_keys(PG_FUNCTION_ARGS) ...@@ -535,7 +535,6 @@ jsonb_object_keys(PG_FUNCTION_ARGS)
{ {
FuncCallContext *funcctx; FuncCallContext *funcctx;
OkeysState *state; OkeysState *state;
int i;
if (SRF_IS_FIRSTCALL()) if (SRF_IS_FIRSTCALL())
{ {
...@@ -598,12 +597,6 @@ jsonb_object_keys(PG_FUNCTION_ARGS) ...@@ -598,12 +597,6 @@ jsonb_object_keys(PG_FUNCTION_ARGS)
SRF_RETURN_NEXT(funcctx, CStringGetTextDatum(nxt)); SRF_RETURN_NEXT(funcctx, CStringGetTextDatum(nxt));
} }
/* cleanup to reduce or eliminate memory leaks */
for (i = 0; i < state->result_count; i++)
pfree(state->result[i]);
pfree(state->result);
pfree(state);
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
} }
...@@ -706,7 +699,6 @@ json_object_keys(PG_FUNCTION_ARGS) ...@@ -706,7 +699,6 @@ json_object_keys(PG_FUNCTION_ARGS)
{ {
FuncCallContext *funcctx; FuncCallContext *funcctx;
OkeysState *state; OkeysState *state;
int i;
if (SRF_IS_FIRSTCALL()) if (SRF_IS_FIRSTCALL())
{ {
...@@ -755,12 +747,6 @@ json_object_keys(PG_FUNCTION_ARGS) ...@@ -755,12 +747,6 @@ json_object_keys(PG_FUNCTION_ARGS)
SRF_RETURN_NEXT(funcctx, CStringGetTextDatum(nxt)); SRF_RETURN_NEXT(funcctx, CStringGetTextDatum(nxt));
} }
/* cleanup to reduce or eliminate memory leaks */
for (i = 0; i < state->result_count; i++)
pfree(state->result[i]);
pfree(state->result);
pfree(state);
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
} }
......
...@@ -706,7 +706,6 @@ tsvector_unnest(PG_FUNCTION_ARGS) ...@@ -706,7 +706,6 @@ tsvector_unnest(PG_FUNCTION_ARGS)
} }
else else
{ {
pfree(tsin);
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment