Skip to content
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

BUG: memleak part 4 #825

Merged
merged 2 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions darshan-util/darshan-logutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,20 @@ void darshan_log_get_name_records(darshan_fd fd,
HASH_ITER(hlink, name_hash, curr, tmp)
{
(*name_records)[i].id = curr->name_record->id;
(*name_records)[i].name = curr->name_record->name;
/* NOTE: darshan_log_get_namehash() call above returns a
* hash table that has allocated name record memory for records
* in the log file. This hash table is not exposed to callers,
* though, so it's this function's responsibility to destroy the
* table and free corresponding memory before returning, as is
* done below. This also requires that we strdup() record names
* that are returned to callers, who are then responsible for
* freeing this memory, just as they are responsible for freeing
* the name_records array allocated above.
*/
(*name_records)[i].name = strdup(curr->name_record->name);
HASH_DELETE(hlink, name_hash, curr);
free(curr->name_record);
free(curr);
i++;
}

Expand Down Expand Up @@ -2183,7 +2196,20 @@ void darshan_log_get_filtered_name_records(darshan_fd fd,
HASH_ITER(hlink, name_hash, curr, tmp)
{
(*name_records)[i].id = curr->name_record->id;
(*name_records)[i].name = curr->name_record->name;
/* NOTE: darshan_log_get_filtered_namehash() call above returns a
* hash table that has allocated name record memory for records
* in the log file. This hash table is not exposed to callers,
* though, so it's this function's responsibility to destroy the
* table and free corresponding memory before returning, as is
* done below. This also requires that we strdup() record names
* that are returned to callers, who are then responsible for
* freeing this memory, just as they are responsible for freeing
* the name_records array allocated above.
*/
(*name_records)[i].name = strdup(curr->name_record->name);
HASH_DELETE(hlink, name_hash, curr);
free(curr->name_record);
free(curr);
i++;
}

Expand Down
5 changes: 4 additions & 1 deletion darshan-util/pydarshan/darshan/backend/cffi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def log_get_name_records(log):

for i in range(0, cnt[0]):
name_records[nrecs[0][i].id] = ffi.string(nrecs[0][i].name).decode("utf-8")

libdutil.darshan_free(nrecs[0][i].name)
libdutil.darshan_free(nrecs[0])

# add to cache
log['name_records'] = name_records
Expand Down Expand Up @@ -277,6 +278,8 @@ def log_lookup_name_records(log, ids=[]):

for i in range(0, cnt[0]):
name_records[nrecs[0][i].id] = ffi.string(nrecs[0][i].name).decode("utf-8")
libdutil.darshan_free(nrecs[0][i].name)
libdutil.darshan_free(nrecs[0])

# add to cache
log['name_records'] = name_records
Expand Down