-
Notifications
You must be signed in to change notification settings - Fork 297
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?
Conversation
@@ -80,14 +80,16 @@ DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *dat | |||
data->ecuid = NULL; | |||
} | |||
|
|||
if (data->log != NULL) | |||
fclose(data->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
@@ -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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
@michael-methner
I did a test to remove fclose, and the results are as follows: fclose is necessary, and the currently submitted code is necessary.
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 comment
The 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 comment
The 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 comment
The 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?
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
#655