-
Notifications
You must be signed in to change notification settings - Fork 298
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
Solve compress lead mem leak #666
base: master
Are you sure you want to change the base?
Changes from 3 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 |
---|---|---|
|
@@ -371,13 +371,15 @@ int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, | |
} | ||
|
||
char* suffix = NULL; | ||
for (i = 0; i < cnt; i++) { | ||
if (config->gzip_compression) { | ||
if (config->gzip_compression) { | ||
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. I think allocating the suffix here multiple times in the loops was the only cause for the memory leak. Or is there another memleak fixed in this PR? 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. Thank you, I will test this case separately when I have time to see if it matches the guess 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.
After testing, it was found that there are two main reasons for memory leaks: 1. fclose needs to be added 2.Allocate memory in a loop |
||
suffix = strdup(".dlt.gz"); | ||
} | ||
else { | ||
suffix = strdup(".dlt"); | ||
} | ||
|
||
for (i = 0; i < cnt; i++) { | ||
|
||
int len = 0; | ||
len = strlen(file_name); | ||
|
@@ -501,6 +503,7 @@ DLT_STATIC void dlt_logstorage_open_log_output_file(DltLogStorageFilterConfig *c | |
#ifdef DLT_LOGSTORAGE_USE_GZIP | ||
dlt_vlog(LOG_DEBUG, "%s: Opening GZIP log file\n", __func__); | ||
config->gzlog = gzdopen(config->fd, mode); | ||
config->log = file; | ||
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. there should be no need to store config->log here. As per my understanding gzclose() will close the passed fd from gzdopen() 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. According to my tests, after gzclose, fclose is also needed. This part of the test is included in #655 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. @michael-methner |
||
#endif | ||
} else { | ||
dlt_vlog(LOG_DEBUG, "%s: Opening log file\n", __func__); | ||
|
@@ -912,6 +915,11 @@ DLT_STATIC void dlt_logstorage_close_file(DltLogStorageFilterConfig *config) | |
gzclose(config->gzlog); | ||
config->gzlog = NULL; | ||
} | ||
|
||
if (config->log) { | ||
hush-soul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fclose(config->log); | ||
config->log = NULL; | ||
} | ||
#endif | ||
if (config->log) { | ||
fclose(config->log); | ||
|
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.
Could you explain a little bit why we move the code here to other lines?
Is there any reasons for closing the gzip first and then close the log?
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.
Yes, the order of opening is fopen gzipopen, so I think the order of closing is best gzclose, fclose