librpipTransactionDestroy
uint32_t librpipTransactionDestroy(struct librpip_tx* t);
Description
Destroys a transaction, removing all malloc’d buffers created through message add calls etc. Transactions need to be destroyed at the end of their useful life.
Note that librpipTransactionDestroy() does not protect against double free. If you have a situation where you need to create and destroy the same transaction often and cannot keep track of the state of the transaction then set the transaction to 0 (null) after destroying it. That way if a 2nd call to librpipTransactionDestroy() is made the free() within it will just do a nop and no double free will occur.
Parameters
- struct librpip_tx* t
A pointer to a transaction created from a previous librpipTransactionCreate().
Returns
0 on failure or 1 on success.
Example
Create a transaction to read an I2C sensor, use the transaction then destroy it:
uint32_t feature_set,i; uint8_t result; struct librpip_tx* MySensor; feature_set = librpipInit(LIBRPIP_BOARD_DETECT, LIBRPIP_FLAG_DEBUG_ON, 0); MySensor=librpipTransactionCreate(LIBRPIP_TX_MODE_I2C, 8); librpipTransactionMsgAddRegRead(MySensor, 0x01, 1); for(i=0;i<5;i++) { librpipTransactionSend(MySensor, 0, 0x30); librpipTransactionRead(MySensor, &result, 1); fprintf(stdout,"The sensor is %u\n",result); } librpipTransactionDestroy(MySensor); librpipClose();