Browse code

Fix slow memory drain on each client renegotiation.

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

Gert Doering authored on 2013/10/24 00:54:05
Showing 3 changed files
... ...
@@ -327,19 +327,28 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)
327 327
 #endif
328 328
 {
329 329
   void *ret;
330
-  struct gc_entry *e;
331
-  ASSERT (NULL != a);
332
-
330
+  if (a)
331
+    {
332
+      struct gc_entry *e;
333 333
 #ifdef DMALLOC
334
-  e = (struct gc_entry *) openvpn_dmalloc (file, line, size + sizeof (struct gc_entry));
334
+      e = (struct gc_entry *) openvpn_dmalloc (file, line, size + sizeof (struct gc_entry));
335 335
 #else
336
-  e = (struct gc_entry *) malloc (size + sizeof (struct gc_entry));
336
+      e = (struct gc_entry *) malloc (size + sizeof (struct gc_entry));
337 337
 #endif
338
-  check_malloc_return (e);
339
-  ret = (char *) e + sizeof (struct gc_entry);
340
-  e->next = a->list;
341
-  a->list = e;
342
-
338
+      check_malloc_return (e);
339
+      ret = (char *) e + sizeof (struct gc_entry);
340
+      e->next = a->list;
341
+      a->list = e;
342
+    }
343
+  else
344
+    {
345
+#ifdef DMALLOC
346
+      ret = openvpn_dmalloc (file, line, size);
347
+#else
348
+      ret = malloc (size);
349
+#endif
350
+      check_malloc_return (ret);
351
+    }
343 352
 #ifndef ZERO_BUFFER_ON_ALLOC
344 353
   if (clear)
345 354
 #endif
... ...
@@ -3030,7 +3030,7 @@ do_close_ifconfig_pool_persist (struct context *c)
3030 3030
 static void
3031 3031
 do_inherit_env (struct context *c, const struct env_set *src)
3032 3032
 {
3033
-  c->c2.es = env_set_create (&c->c2.gc);
3033
+  c->c2.es = env_set_create (NULL);
3034 3034
   c->c2.es_owned = true;
3035 3035
   env_set_inherit (c->c2.es, src);
3036 3036
 }
... ...
@@ -171,7 +171,7 @@ openvpn_main (int argc, char *argv[])
171 171
 	  gc_init (&c.gc);
172 172
 
173 173
 	  /* initialize environmental variable store */
174
-	  c.es = env_set_create (&c.gc);
174
+	  c.es = env_set_create (NULL);
175 175
 #ifdef WIN32
176 176
 	  set_win_sys_path_via_env (c.es);
177 177
 #endif