]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Fix slow memory drain on each client renegotiation.
authorGert Doering <gert@greenie.muc.de>
Wed, 23 Oct 2013 15:54:05 +0000 (17:54 +0200)
committerGert Doering <gert@greenie.muc.de>
Sun, 17 Nov 2013 12:57:14 +0000 (13:57 +0100)
This reverts commit bee92b479414d12035b0422f81ac5fcfe14fa645 and parts
of commit dc7be6d078ba106f9b0de12f3e879c3561c3c537, as these introduced a
subtle memory drain on client renegotiations (es->gc got initialized,
which led to "unused" gc_entry records accumulating while a client is
connected).

Setting es->gc=NULL causes env_set_add_nolock() / remove_env_item() to
free() allocated and no longer used strings in the es, while an active
gc would leave them for cleanup with gc_free() at client disconnect time.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Conflicts:
src/openvpn/buffer.c
Acked-by: David Sommerseth <dazo@users.sourceforge.net>
Message-Id: <20131023162618.GP161@greenie.muc.de>
URL: http://article.gmane.org/gmane.network.openvpn.devel/7939

src/openvpn/buffer.c
src/openvpn/init.c
src/openvpn/openvpn.c

index 56d14b1aace3ad077feec6ebdf901521e051bb67..fb3b52d1747fff1a485693d67524fcd5ebf055c4 100644 (file)
@@ -327,19 +327,28 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)
 #endif
 {
   void *ret;
-  struct gc_entry *e;
-  ASSERT (NULL != a);
-
+  if (a)
+    {
+      struct gc_entry *e;
 #ifdef DMALLOC
-  e = (struct gc_entry *) openvpn_dmalloc (file, line, size + sizeof (struct gc_entry));
+      e = (struct gc_entry *) openvpn_dmalloc (file, line, size + sizeof (struct gc_entry));
 #else
-  e = (struct gc_entry *) malloc (size + sizeof (struct gc_entry));
+      e = (struct gc_entry *) malloc (size + sizeof (struct gc_entry));
 #endif
-  check_malloc_return (e);
-  ret = (char *) e + sizeof (struct gc_entry);
-  e->next = a->list;
-  a->list = e;
-
+      check_malloc_return (e);
+      ret = (char *) e + sizeof (struct gc_entry);
+      e->next = a->list;
+      a->list = e;
+    }
+  else
+    {
+#ifdef DMALLOC
+      ret = openvpn_dmalloc (file, line, size);
+#else
+      ret = malloc (size);
+#endif
+      check_malloc_return (ret);
+    }
 #ifndef ZERO_BUFFER_ON_ALLOC
   if (clear)
 #endif
index 031fb2040a118a5ec51438037acdc4b1c4edc0bf..ba15fe311a9da28bbfb3cdae772c0fc07d76d012 100644 (file)
@@ -3030,7 +3030,7 @@ do_close_ifconfig_pool_persist (struct context *c)
 static void
 do_inherit_env (struct context *c, const struct env_set *src)
 {
-  c->c2.es = env_set_create (&c->c2.gc);
+  c->c2.es = env_set_create (NULL);
   c->c2.es_owned = true;
   env_set_inherit (c->c2.es, src);
 }
index 104c9e9399c65e5d0d3e066a0875448f4ad5edc2..5125eae9267b44457118abbfd2f10341df5567a8 100644 (file)
@@ -171,7 +171,7 @@ openvpn_main (int argc, char *argv[])
          gc_init (&c.gc);
 
          /* initialize environmental variable store */
-         c.es = env_set_create (&c.gc);
+         c.es = env_set_create (NULL);
 #ifdef WIN32
          set_win_sys_path_via_env (c.es);
 #endif