Skip to content

Commit

Permalink
fix: Avoid free NULL pointer of bundle (#7)
Browse files Browse the repository at this point in the history
Avoid assigning NULL when pointer of pointer, bundle
is NULL.

Co-authored-by: Sam Chen <[email protected]>
  • Loading branch information
howjmay and Sam Chen authored Jan 31, 2020
1 parent e97da0f commit 50aeee0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion common/model/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ static retcode_t validate_signatures(bundle_transactions_t const *const bundle,

void bundle_transactions_new(bundle_transactions_t **const bundle) { utarray_new(*bundle, &bundle_transactions_icd); }

void bundle_transactions_free(bundle_transactions_t **const bundle) {
retcode_t bundle_transactions_free(bundle_transactions_t **const bundle) {
if (!bundle || !*bundle) {
return RC_NULL_PARAM;
}

if (bundle && *bundle) {
utarray_free(*bundle);
}
*bundle = NULL;

return RC_OK;
}

retcode_t bundle_transactions_add(bundle_transactions_t *const bundle, iota_transaction_t const *const transaction) {
Expand Down
3 changes: 2 additions & 1 deletion common/model/bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ void bundle_transactions_new(bundle_transactions_t **const bundle);
* @brief Frees a bundle object.
*
* @param[in] bundle A bundle object.
* @return #retcode_t
*/
void bundle_transactions_free(bundle_transactions_t **const bundle);
retcode_t bundle_transactions_free(bundle_transactions_t **const bundle);

/**
* @brief Adds a transaction to the bundle.
Expand Down

0 comments on commit 50aeee0

Please sign in to comment.