If a UDF must allocate memory, use Teradata C library functions FNC_malloc and FNC_free instead of standard C library functions malloc and free. The sqltypes_td.h header file redefines malloc and free to call FNC_malloc and FNC_free.
FNC_free and FNC_malloc make sure the UDF releases all memory before exiting and give an exception on the transaction if the UDF does not release its temporary memory. This prevents memory leaks in the database.
If you call malloc and free directly, a memory leak may occur even if the UDF frees up memory correctly. A UDF can end while running if a user ends the transaction, or if the transaction ends because of a constraint violation on another node unbeknownst to the running UDF.
When you develop, test, and debug a standalone UDF, include malloc.h header file and use standard malloc and free C library functions.
When you use CREATE FUNCTION to submit UDF source code to server, do not include malloc.h header file or use definitions of malloc and free from sqltypes_td.h header file. Use the definitions when submitting UDF source code to server, not when submitting UDF objects.