malloc and free | Standard C Library Functions | Teradata Vantage - malloc and free - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-03-30
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
qnu1472247494689
lifecycle
latest
Product Category
Teradata Vantageā„¢

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.