MCPcopy Create free account
hub / github.com/apache/cloudberry / plpgsql_free_function_memory

Function plpgsql_free_function_memory

src/pl/plpgsql/src/pl_funcs.c:724–778  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

722}
723
724void
725plpgsql_free_function_memory(PLpgSQL_function *func)
726{
727 int i;
728
729 /* Better not call this on an in-use function */
730 Assert(func->use_count == 0);
731
732 /* Release plans associated with variable declarations */
733 for (i = 0; i < func->ndatums; i++)
734 {
735 PLpgSQL_datum *d = func->datums[i];
736
737 switch (d->dtype)
738 {
739 case PLPGSQL_DTYPE_VAR:
740 case PLPGSQL_DTYPE_PROMISE:
741 {
742 PLpgSQL_var *var = (PLpgSQL_var *) d;
743
744 free_expr(var->default_val);
745 free_expr(var->cursor_explicit_expr);
746 }
747 break;
748 case PLPGSQL_DTYPE_ROW:
749 break;
750 case PLPGSQL_DTYPE_REC:
751 {
752 PLpgSQL_rec *rec = (PLpgSQL_rec *) d;
753
754 free_expr(rec->default_val);
755 }
756 break;
757 case PLPGSQL_DTYPE_RECFIELD:
758 break;
759 default:
760 elog(ERROR, "unrecognized data type: %d", d->dtype);
761 }
762 }
763 func->ndatums = 0;
764
765 /* Release plans in statement tree */
766 if (func->action)
767 free_block(func->action);
768 func->action = NULL;
769
770 /*
771 * And finally, release all memory except the PLpgSQL_function struct
772 * itself (which has to be kept around because there may be multiple
773 * fn_extra pointers to it).
774 */
775 if (func->fn_cxt)
776 MemoryContextDelete(func->fn_cxt);
777 func->fn_cxt = NULL;
778}
779
780
781/**********************************************************************

Callers 2

plpgsql_inline_handlerFunction · 0.85
delete_functionFunction · 0.85

Calls 2

free_exprFunction · 0.85
free_blockFunction · 0.85

Tested by

no test coverage detected