Re: [Openvpn-devel] Memory of server keeps increasing with key negotiations

2008-05-29 Thread Martin Gadbois
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Marko Rauhamaa wrote:
> Martin Gadbois :
> 
>> I've looked at the code (Yeah! Open Source) and could not see any
>> lists, or code that accumulates data, apart from gc_*().
> 
> There's this weird scheme by which you prepare a memory pool with
> gc_new(). Memory keeps on accumulating in the pool with alloc_buf_gc()
> (in print_sockaddr_ex(), for example). The memory is not freed until the
> whole pool is destroyed with gc_free().

Yep. It seems that whenever env_set_add() is called, context->c2.gc is
used to allocate stuff using gc*() functions at every key renegotiation.

The environement list is kept up-to-date, but all elements from this
list is allocated using context->c2.gc, and never freed.

Now, I need to fix that without breaking anything...


- --
== +-+
Martin Gadbois |You are-- J. Steakley,   |
Sr. SW Designer|What you do Armor, 1984  |
Colubris Networks Inc. |When it counts.  |
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIPsQxMPkSU9icdA0RAmHYAJ4yA+7Vw3SVY7X/Q+pH5icLkwlu/ACcDubu
Y6+Q9emSaFl2kbwkOmInPCc=
=ZRWI
-END PGP SIGNATURE-



Re: [Openvpn-devel] Memory of server keeps increasing with key negotiations

2008-05-29 Thread Martin Gadbois
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Martin Gadbois wrote:

> Using OpenVPN 2.0.5 and 2.0.9, I notice that an somewhat idle connection
> increases the RSS of the server process linearly with time.
> 

Here is my patch to fix this issue. It does create (according to
valgrind) a memory leak, but it does not increase with time. Feel free
to fix it better...

I short, environments values were allocated using gc*(), and every key
change the environement list changes, but the allocated values stayed in
the context's gc.

I modified the environement values to always allocate using malloc() and
always free() values when the env list changes.


- --
== +-+
Martin Gadbois |You are-- J. Steakley,   |
Sr. SW Designer|What you do Armor, 1984  |
Colubris Networks Inc. |When it counts.  |
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIPtCmMPkSU9icdA0RAiXTAJ4g3qzaubnyRTOCsCEF9Iz3BU+2AQCeMzzE
/7mbJluQBOfzjy4jph4T4RI=
=fksj
-END PGP SIGNATURE-
diff -ur openvpn-2.0.5-org/misc.c openvpn-2.0.5/misc.c
--- openvpn-2.0.5-org/misc.c2005-11-01 06:06:11.0 -0500
+++ openvpn-2.0.5/misc.c2008-05-29 11:37:05.0 -0400
@@ -651,7 +652,7 @@
prev->next = current->next;
  else
*list = current->next;
- if (do_free)
+//   if (do_free)
{
  memset (current->string, 0, strlen (current->string));
  free (current->string);
@@ -671,9 +672,10 @@

   ASSERT (str);
   ASSERT (list);
-
-  ALLOC_OBJ_GC (item, struct env_item, gc);
-  item->string = do_alloc ? string_alloc (str, gc): str;
+   dmsg(M_WARN,"ENV: Adding %s %s",str,do_alloc?"Alloc":"");
+  ALLOC_OBJ (item, struct env_item);
+//  item->string = do_alloc ? string_alloc (str, gc): str;
+  item->string = strdup(str);
   item->next = *list;
   *list = item;
 }