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

Memory leak when using event broker #664

Closed
gzalo opened this issue Jul 23, 2019 · 5 comments
Closed

Memory leak when using event broker #664

gzalo opened this issue Jul 23, 2019 · 5 comments
Labels
Milestone

Comments

@gzalo
Copy link

gzalo commented Jul 23, 2019

Hi. I've found a memory in run_async_service_check and run_async_host_check, when using event brokers (in my case mod_gearman 3.10). If lots of checks per second are running, this can leak a couple of GBs per day.

3.1.0 leak

nagioscore/base/checks.c

Lines 3186 to 3193 in a7346f7

/* neb module wants to override the service check - perhaps it will check the service itself */
if (neb_result == NEBERROR_CALLBACKOVERRIDE) {
clear_volatile_macros_r(&mac);
hst->latency = old_latency;
free_check_result(cr);
my_free(processed_command);
return OK;
}

The calloc'd variable "cr" (which contains the tentative check results) has its contents cleared but is never free'd.
When using mod-gearman, the memory for the check results is allocated when the results of a check are ready, and thus the memory allocated by Nagios itself will leak.
There is no way to free it on the NEB module without making the nagios process crash when it calls free_check_result, since the module can't set the cr variable to null (it will keep pointing to recently free'd memory).

Thanks, Gonzalo

@sawolf
Copy link
Contributor

sawolf commented Jul 23, 2019

Thanks for reporting this! I'll try to look into this sometime this week.

@sawolf
Copy link
Contributor

sawolf commented Jul 24, 2019

Okay, I had time to look at this.

It looks like free_check_result does not free the cr * itself, because in some places this struct is allocated on the stack. Elsewhere in the program, free_check_result() is followed by freeing the pointer separately.

I've set up a branch at https://github.com/Madlohe/nagioscore/tree/bug-664/leaky-MG-check-results which seems to be working. Would you be willing to compile from there and verify that this fixes the issue for you?

@sawolf sawolf added this to the 4.4.4 milestone Jul 24, 2019
@gzalo
Copy link
Author

gzalo commented Jul 25, 2019

Would you be willing to compile from there and verify that this fixes the issue for you?

Sure, I will be testing it today. I will keep you posted. Thanks a lot!

@gzalo
Copy link
Author

gzalo commented Jul 25, 2019

It appears to be working fine, the memory leak is gone! Thanks

@sawolf
Copy link
Contributor

sawolf commented Jul 25, 2019

Excellent! Merging and closing now.

@sawolf sawolf closed this as completed Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants