Skip to content

Commit

Permalink
Merge pull request areaDetector#390 from hinxx/master
Browse files Browse the repository at this point in the history
fix memory leak by calling H5close() in NDFileHDF5::closeFile()
  • Loading branch information
MarkRivers authored Mar 28, 2019
2 parents c0786ba + 5867b73 commit c63d008
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ADApp/pluginSrc/NDFileHDF5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1658,10 +1658,20 @@ asynStatus NDFileHDF5::closeFile()
"%s::%s Closing file not totally clean. Attributes remaining=%d\n",
driverName, functionName, obj_count);
}
obj_count = (int)H5Fget_obj_count(this->file, H5F_OBJ_ALL);
if (obj_count > 1){
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"%s::%s Closing file not totally clean. Other remaining=%d\n",
driverName, functionName, obj_count);
}

// Close the HDF file
H5Fclose(this->file);
this->file = 0;
// Flush all data to disk, close all open HDF5 objects,
// and clean up all memory used by the HDF5 library
// to avoid memory leaks
H5close();

// At this point we can clear the SWMR active flag, whether we were running
// in SWMR mode or not
Expand Down Expand Up @@ -2689,7 +2699,7 @@ asynStatus NDFileHDF5::createAttributeDataset(NDArray *pArray)
// In here we need to open the dataset for writing

hdf5::DataSource dsource = dset->data_source();
std::string atName = std::string(epicsStrDup(ndAttr->getName()));
std::string atName = std::string(ndAttr->getName());
NDFileHDF5AttributeDataset *attDset = new NDFileHDF5AttributeDataset(this->file, atName, ndAttr->getDataType());
attDset->setDsetName(dset->get_name());
attDset->setWhenToSave(dsource.get_when_to_save());
Expand Down Expand Up @@ -2755,6 +2765,9 @@ asynStatus NDFileHDF5::createAttributeDataset(NDArray *pArray)
if(def_group != NULL){
H5Gclose(groupDefault);
}
if (numCapture) {
free(numCapture);
}

return asynSuccess;
}
Expand Down

0 comments on commit c63d008

Please sign in to comment.