andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From a720e002751815323a295e11e77c56d7ce38314e Mon Sep 17 00:00:00 2001
From: Simon Pichugin <spichugi@redhat.com>
Date: Fri, 27 Mar 2020 11:35:55 +0100
Subject: [PATCH] Issue 50984 - Memory leaks in disk monitoring

Description: Reset dirs pointer every time we free it.
The code may be changed in the future so we should make it
more robust.

https://pagure.io/389-ds-base/issue/50984

Reviewed by: spichugi, tbordaz (one line commit rule)
---
 ldap/servers/slapd/daemon.c | 2 ++
 ldap/servers/slapd/main.c   | 1 +
 2 files changed, 3 insertions(+)

diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
index 542d31037..a70f40316 100644
--- a/ldap/servers/slapd/daemon.c
+++ b/ldap/servers/slapd/daemon.c
@@ -613,6 +613,7 @@ disk_monitoring_thread(void *nothing __attribute__((unused)))
                         }
                     }
                     slapi_ch_array_free(dirs);
+                    dirs = NULL;
                     return;
                 }
                 /*
@@ -712,6 +713,7 @@ disk_monitoring_thread(void *nothing __attribute__((unused)))
             }
         }
         slapi_ch_array_free(dirs);
+        dirs = NULL; /* now it is not needed but the code may be changed in the future and it'd better be more robust */
         g_set_shutdown(SLAPI_SHUTDOWN_DISKFULL);
         return;
 }
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
index 1f8b01959..e54b8e1c5 100644
--- a/ldap/servers/slapd/main.c
+++ b/ldap/servers/slapd/main.c
@@ -958,6 +958,7 @@ main(int argc, char **argv)
             goto cleanup;
         }
         slapi_ch_array_free(dirs);
+        dirs = NULL;
     }
     /* log the max fd limit as it is typically set in env/systemd */
     slapi_log_err(SLAPI_LOG_INFO, "main",
-- 
2.26.2