-
-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removes C++ dependency on H5private.h #774
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
#include <iostream> | ||
#include <string> | ||
|
||
#include "H5private.h" // for HDfree | ||
#include "H5Include.h" | ||
#include "H5Exception.h" | ||
#include "H5IdComponent.h" | ||
|
@@ -717,8 +716,8 @@ DataSet::p_read_fixed_len(const hid_t mem_type_id, const hid_t mem_space_id, con | |
|
||
// If there is data, allocate buffer and read it. | ||
if (data_size > 0) { | ||
char *strg_C = new char[data_size + 1]; | ||
HDmemset(strg_C, 0, data_size + 1); // clear buffer | ||
// Create buffer for C string | ||
char *strg_C = new char[data_size + 1](); | ||
|
||
herr_t ret_value = H5Dread(id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, strg_C); | ||
|
||
|
@@ -759,7 +758,7 @@ DataSet::p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space_id, | |
|
||
// Get string from the C char* and release resource allocated by C API | ||
strg = strg_C; | ||
HDfree(strg_C); | ||
free(strg_C); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be delete? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. We get that memory from the HDF5 C library, so it wasn't allocated with new. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I remember why I used HDfree, because of the very reason you said here. The right fix is to remove "new char[data_size + 1];" above. The library will allocate for strg_C. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That new char[data_size + 1] line is in a different function. In this function, strg_C is just defined as a char pointer and not initialized. |
||
} | ||
|
||
#ifndef DOXYGEN_SHOULD_SKIP_THIS | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. You can't mix malloc/free and new/delete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. It was an accident, but you fixed it by changing HDfree to free, and I asked should it be delete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be delete[]. If you expand the code, you'll see that srgc_C is an unallocated char pointer. The memory is allocated by the library and should be freed using free().