NULL_PTR. If

Introductory Example

function calls after the do-whileconstruct. That way, even if there is an error somewhere and the program breaks out of the do-whilebefore executing all the calls within the do-while, the Destroy functions will execute. In case the error occurs before an object has been created, it is a good idea to initialize objects to

an object is NULL_PTR, the Destroy function does nothing.

Chapter 4 of the Reference Manual gives the description and prototype of the Destroy functions:

void B_DestroyKeyObject (

 

B_KEY_OBJ

*keyObject

/* pointer to key object */

);

 

 

void B_DestroyAlgorithmObject (

 

B_ALGORITHM_OBJ *algorithmObject

/* pointer to algorithm object */

);

 

 

 

 

 

For our example, we use the following:

B_DestroyKeyObject (&rc4Key);

B_DestroyAlgorithmObject (&rc4Encrypter);

Note: Following these calls, rc4Key and rc4Encrypter will be set to NULL if the objects were disposed of properly.

In addition to destroying any objects that you created, any memory you allocated must be freed when you are done with it. This means that each T_malloc must have a corresponding T_free. Placing the T_free after the do-whileguarantees that it will be called even if there is an error somewhere. However, there is a concern that if there is an error before the T_malloc and the program breaks out of the do-whilebefore memory is allocated, then T_free will be called without a corresponding T_malloc. That is why it is important to initialize the pointer to NULL_PTR. If the argument to T_free is NULL_PTR, the extra call to T_free does nothing.

See Chapter 4 of the Reference Manual for the T_free prototype:

void T_free (

 

POINTER block

/* block address */

);

 

 

 

C h a p t e r 2 Q u i c k S t a r t

2 1

Page 43
Image 43
RSA Security 5.2.2 manual For our example, we use the following, Pointer to key object, Balgorithmobj * algorithmObject