PreviousNext

Memory Allocation Routines

The stubs will do their best to allocate any new memory required for marshalled pointed-to nodes so that the marshalling is transparent to the application. On the server side, stub allocated memory exists for the scope of the manager routine call. The stub frees such memory once the nodes have been marshalled. On the client side, however, the stubs obviously cannot free the memory they have marshalled since they are returning the data to the client application. Therefore, in order to avoid memory leaks, when a client makes an RPC that results in the client stub allocating memory, the client application needs to call rpc_sm_client_free( ) to free the pointed-to memory.

When a server manager routine needs to allocate new memory for a pointed-to node, it can do so either statically or by making a call to a memory allocation routine. In the latter case, however, the manager cannot deallocate the memory it has allocated, since the pointer must be valid when the call returns (so that the stubs can marshall the data.) Only the stub can free such memory. In order to permit this, server managers need to call rpc_sm_allocate( ) to allocate memory for parameters. The stubs free all memory allocated by rpc_sm_allocate( ) once they have marshalled the required data, thus avoiding memory leaks.