Skip to content

Commit

Permalink
Merge pull request #81 from ImagingDataCommons/fix-double-free
Browse files Browse the repository at this point in the history
fix a double free error
  • Loading branch information
jcupitt authored Feb 16, 2024
2 parents 345eda5 + 3661aa4 commit e0f07cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* improve memory usage [bgilbert]
* fix docs build with LLVM != 14 [bgilbert]
* improve thread safety docs [mollyclaretechcyte]
* fix a double free error and clarify docs on pointer ownership [dtatsis]

## 1.0.5, 9/10/23

Expand Down
14 changes: 10 additions & 4 deletions include/dicom/dicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,11 @@ DcmDataSet *dcm_dataset_clone(DcmError **error, const DcmDataSet *dataset);
* :param dataset: Pointer to Data Set
* :param element: Pointer to Data Element
*
* The object takes over ownership of the memory referenced by `element`
* and frees it when the object is destroyed or if the insert operation fails.
* On success, the dataset takes over ownership of `element`
* and frees it when the dataset is destroyed.
*
* If the insert operation fails, ownership does not pass and the caller is
* responsible for freeing `element`.
*
* :return: Whether insert operation was successful
*/
Expand Down Expand Up @@ -1198,8 +1201,11 @@ DcmSequence *dcm_sequence_create(DcmError **error);
* :param seq: Pointer to Sequence
* :param item: Data Set item
*
* The object takes over ownership of the memory referenced by `item`
* and frees it when the object is destroyed or if the append operation fails.
* On success, the sequence takes over ownership of `item`
* and frees it when the sequence is destroyed.
*
* If the append fails, ownership does not pass and the caller is
* responsible for freeing `item`.
*
* :return: Whether append operation was successful
*/
Expand Down
3 changes: 1 addition & 2 deletions src/dicom-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ DcmDataSet *dcm_dataset_clone(DcmError **error, const DcmDataSet *dataset)
return NULL;
}
if (!dcm_dataset_insert(error, cloned_dataset, cloned_element)) {
dcm_element_destroy(cloned_element);
dcm_dataset_destroy(cloned_dataset);
return NULL;
}
Expand Down Expand Up @@ -1435,7 +1436,6 @@ bool dcm_dataset_insert(DcmError **error,
"Element already exists",
"Inserting Data Element '%08x' into Data Set failed",
element->tag);
dcm_element_destroy(element);
return false;
}

Expand Down Expand Up @@ -1707,7 +1707,6 @@ DcmDataSet *dcm_sequence_steal(DcmError **error,
}

DcmDataSet *result = seq_item->dataset;
//dcm_dataset_lock(result);
seq_item->dataset = NULL;
// this will free the SequenceItem
utarray_erase(seq->items, index, 1);
Expand Down

0 comments on commit e0f07cf

Please sign in to comment.