17.10 - Usage Notes - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

FNC_free is the equivalent of free for use by UDFs, UDMs, table operator, contract function and external stored procedures.

The sqltypes_td.h header file redefines free to call FNC_free.

WHEN you … THEN …
develop, test, and debug a UDF, UDM, or external stored procedure standalone include the malloc.h header file and use the standard malloc and free C library functions.
install your UDF, UDM, or external stored procedure on the server do not include the malloc.h header file and use the definitions of malloc and free from the sqltypes_td.h header file.

Note that the definitions are used when submitting source code to the server, but not when submitting objects.

FNC_free checks to make sure the UDF, UDM, or external stored procedure releases all memory before exiting and gives an exception on the transaction if the UDF, UDM, or external stored procedure does not release all temporary memory it allocated. This is to prevent memory leaks in the database.

If you circumvent the logic to call malloc and free directly, then there is a good chance that a memory leak could occur even if the UDF, UDM, or external stored procedure frees up memory correctly. The reason is that a UDF, UDM, or external stored procedure can abort while it is running if a user aborts the transaction, or if the transaction aborts because of some constraint violation that might occur on another node unbeknownst to the running UDF, UDM, or external stored procedure.