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
085b6b667 and
b4570d33a. 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
uargs->offset++;
SRF_RETURN_NEXT(fctx, result);
}
- else
- {
- pfree(uargs->page);
- pfree(uargs);
- SRF_RETURN_DONE(fctx);
- }
+
+ SRF_RETURN_DONE(fctx);
}
/*-------------------------------------------------------
uargs->offset++;
SRF_RETURN_NEXT(fctx, result);
}
- else
- {
- pfree(uargs);
- SRF_RETURN_DONE(fctx);
- }
+
+ SRF_RETURN_DONE(fctx);
}
/* Number of output arguments (columns) for bt_metap() */
SRF_RETURN_NEXT(fctx, result);
}
- else
- SRF_RETURN_DONE(fctx);
+
+ SRF_RETURN_DONE(fctx);
}
SRF_RETURN_NEXT(fctx, result);
}
- else
- {
- pfree(uargs);
- SRF_RETURN_DONE(fctx);
- }
+
+ SRF_RETURN_DONE(fctx);
}
/* ------------------------------------------------
SRF_RETURN_NEXT(funccxt, HeapTupleGetDatum(tuple));
}
- if (multi->nmembers > 0)
- pfree(multi->members);
- pfree(multi);
-
SRF_RETURN_DONE(funccxt);
}
st->cur++;
return result;
}
- if (st->list)
- pfree(st->list);
- pfree(st);
return (Datum) 0;
}
st->cur++;
return result;
}
- else
- {
- if (st->list)
- pfree(st->list);
- pfree(st);
- }
return (Datum) 0;
}
{
FuncCallContext *funcctx;
OkeysState *state;
- int i;
if (SRF_IS_FIRSTCALL())
{
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);
}
{
FuncCallContext *funcctx;
OkeysState *state;
- int i;
if (SRF_IS_FIRSTCALL())
{
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);
}
}
else
{
- pfree(tsin);
SRF_RETURN_DONE(funcctx);
}
}