Generated Memory Free Functions

The -genFree option causes functions to be generated that free dynamic memory allocated using the ASN1C run-time memory management functions and macros (rtxMem). By default, all memory held within a context is freed using the rtxMemFree run-time function. It is also possible to free an individual memory item using the rtMemFreePtr function. But it is not possible to free all memory held within a specific generated type container. For example, a SEQUENCE type could contain elements that require dynamic memory. These elements in turn can reference other types that require dynamic memory. The generated memory free functions make it possible to release all memory held within a variable of the type with a single call.

Generated memory free functions are written to the main <module>.c file. This file contains common constants, global variables, and functions that are generic to all type of encode/decode functions. If the -cfile command-line option is used, the functions are written to the specified .c or .cpp file along with all other generated functions. If -maxcfiles is specified, each generated function is written to a separate .c file.

The format of the name of each generated memory free function is as follows:

   asn1Free_[<prefix>]<prodName>

where <prodName> is the name of the ASN.1 production for which the function is being generated and <prefix> is an optional prefix that can be set via a configuration file setting. The configuration setting used to set the prefix is the <typePrefix> element. This element specifies a prefix that will be applied to all generated typedef names and function names for the production.

The calling sequence for each generated memory free function is as follows:

   asn1Free_<name> (OSCTXT* pctxt, <name>* pvalue)

In this definition, <name> denotes the prefixed production name defined above.

The pctxt argument is used to hold the context pointer that the memory to be freed was allocated with. This is a basic "handle" variable that is used to make the function reentrant so it can be used in an asynchronous or threaded application. The user is required to supply a pointer to a variable of this type declared somewhere in his or her or her program.

The pvalue argument is used to pass a pointer to a variable of the item that contains the dynamic memory to be freed.