autofs-5.0.1 - fix memory leak on reload From: Ian Kent <raven@themaw.net> When sending a signal to the automount daemon to re-load the maps a map entry cache is pre-allocated before checking if the entry already exists. If the master map entry was found to exist the pre-allocated cache was not being freed. If there are a large number of entries in the master map and there are frequent re-load requests sent to the daemon the memory leak will cause the system to become unstable fairly quilkly. Since the map entry cache (allocated for each map entry) is fairly large these days (and is configurable) pre-allocating it is no longer a cheap operation. This patch fixes the memory leak and only allocates a map entry cache if the entry does not already exist. --- lib/master.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) --- autofs-5.0.1.orig/lib/master.c +++ autofs-5.0.1/lib/master.c @@ -194,9 +194,15 @@ master_add_map_source(struct master_mape master_source_writelock(entry); - if (!entry->maps) + if (!entry->maps) { + source->mc = cache_init(entry->ap, source); + if (!source->mc) { + master_free_map_source(source, 0); + master_source_unlock(entry); + return NULL; + } entry->maps = source; - else { + } else { struct map_source *this, *last, *next; /* Typically there only a few map sources */ @@ -209,6 +215,13 @@ master_add_map_source(struct master_mape return this; } + source->mc = cache_init(entry->ap, source); + if (!source->mc) { + master_free_map_source(source, 0); + master_source_unlock(entry); + return NULL; + } + last = NULL; next = entry->maps; while (next) {