Moved out of memory prototype to error.h, as the definition is in error.c
PATCH 1/2 Moved out of memory prototype to error.h, as the definition is in error.c
--- buffer.h | 4 +--- error.h | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-)
buffer.h +1 -3
@@ -26,6 +26,7 @@#define BUFFER_H #include "basic.h" +#include "error.h" #define BUF_SIZE_MAX 1000000
@@ -810,8 +811,6 @@ gc_reset (struct gc_arena *a)* Allocate memory to hold a structure */ -void out_of_memory (void ); -#define ALLOC_OBJ (dptr, type) \ { \ check_malloc_return ((dptr) = (type *) malloc (sizeof (type))); \
@@ -862,7 +861,6 @@ void out_of_memory (void);static inline void check_malloc_return (void *p) { -void out_of_memory (void );if (!p)out_of_memory (); }
error.h +3 -0
@@ -244,6 +244,9 @@ HANDLE get_orig_stderr (void);/* exit program */ void openvpn_exit (const int status); +/* exit program on out of memory error */ +void out_of_memory (void ); +/* * Check the return status of read/write routines. */
Signature · 1 line
1.7.5.4
PATCH 2/2 Removed support for calling gc_malloc with a NULL gc_arena struct
--- buffer.c | 29 ++++++++++------------------- 1 files changed, 10 insertions(+), 19 deletions(-)
buffer.c +10 -19
@@ -310,28 +310,19 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)#endif {void *ret; -if (a) - { -struct gc_entry *e; -#ifdef DMALLOC - e = (struct gc_entry *)openvpn_dmalloc (file, line, size +sizeof (struct gc_entry )); -#else - 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; - } -else - { +ASSERT (NULL != a); + +struct gc_entry *e;#ifdef DMALLOC - ret =openvpn_dmalloc (file, line, size); + e = (struct gc_entry *)openvpn_dmalloc (file, line, size +sizeof (struct gc_entry ));#else - ret =malloc (size); + e = (struct gc_entry *)malloc (size +sizeof (struct gc_entry ));#endif -check_malloc_return (ret); - } +check_malloc_return (e); + ret = (char *) e +sizeof (struct gc_entry ); + e->next = a->list; + a->list = e; +#ifndef ZERO_BUFFER_ON_ALLOC if (clear)#endif
Signature · 1 line
1.7.5.4
Re: [Openvpn-devel] [PATCH 2/2] Removed support for calling gc_malloc with a NULL gc_arena struct
Hi,
Quoted 10 lines · Adriaan de Jong
Signed-off-by Adriaan de Jong <[email protected]...>--- buffer.c | 29 ++++++++++------------------- 1 files changed, 10 insertions(+), 19 deletions(-)buffer.c +0
-0
buffer.c gc_malloc (size_t size, bool clear, struct gc_arena *a) · line 315
Quoted 6 lines
buffer.c +0
-3@@ -310,28 +310,19 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)#endif {void *ret; -if (a) - { -struct gc_entry *e;
NACK on that. We discovered that there are use cases where "second-level" callers pass NULL, seemingly on purpose to allocate global memory instead of "in the GC".
main(), in openvpn.c:
/* initialize environmental variable store */
c.es = env_set_create (NULL);... which calls into misc.c:
struct env_set *env_set_create (struct gc_arena *gc)
{
struct env_set *es;
ALLOC_OBJ_CLEAR_GC (es, struct env_set, gc);
es->list = NULL;
es->gc = gc;
return es;
}
... and boom, assert() fail.
Adriaan saw the crash ("my nice OpenBSD test run!!!") and promised to work on this on the way back in the train.
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Re: [Openvpn-devel] [PATCH 2/2] Removed support for calling gc_malloc with a NULL gc_arena struct
Quoted 41 lines · Gert Doering
Hi,
Quoted 10 lines · Adriaan de Jong
Signed-off-by Adriaan de Jong<[email protected]...>--- buffer.c | 29 ++++++++++------------------- 1 files changed, 10 insertions(+), 19 deletions(-)buffer.c +0
-0buffer.c gc_malloc (size_t size, bool clear, struct gc_arena *a) · line 315
Quoted 6 lines
buffer.c +0
-3@@ -310,28 +310,19 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)#endif {void *ret; -if (a) - { -struct gc_entry *e;NACK on that. We discovered that there are use cases where "second-level" callers pass NULL, seemingly on purpose to allocate global memory instead of "in the GC".
main(), inopenvpn.c:/* initialize environmental variable store */ c.es = env_set_create (NULL);... which calls into
misc.c:struct
env_set*env_set_create(structgc_arena*gc){ struct env_set *es; ALLOC_OBJ_CLEAR_GC (es, struct env_set, gc); es->list = NULL; es->gc = gc; return es; }
Quoted 5 lines
... and boom,
assert()fail.Adriaan saw the crash ("my nice OpenBSD test run!!!") and promised to work on this on the way back in the train.
But should this actually call gc_malloc() in this case? gc_malloc is for things which are supposed to be tackled by the garbage collector.
Things aren't too easy here - but I'd rather see us cleaning up this instead of making gc_malloc() vague in its purpose.
$ git grep env_set_create init.c: c->c2.es = env_set_create (NULL); manage.c: struct env_set *es = env_set_create (&gc); misc.c:env_set_create (struct gc_arena *gc) misc.h:struct env_set *env_set_create (struct gc_arena *gc); multi.c: es = env_set_create (&gc); openvpn.c: c.es = env_set_create (NULL);
There are two places where env_set_create() is called with NULL. Let's rather see if we can provide a gc_arena pointer those places instead. Or do something which is more clear in regards to memory allocation in env_set_create().
kind regards,
David Sommerseth
Re: [Openvpn-devel] [PATCH 2/2] Removed support for calling gc_malloc with a NULL gc_arena struct
Hi,
Quoted 63 lines · David Sommerseth
Quoted 42 lines · Gert Doering
Hi,
Quoted 10 lines · Adriaan de Jong
Signed-off-by Adriaan de Jong<[email protected]...>--- buffer.c | 29 ++++++++++------------------- 1 files changed, 10 insertions(+), 19 deletions(-)buffer.c +0
-0buffer.c gc_malloc (size_t size, bool clear, struct gc_arena *a) · line 313
Quoted 7 lines
buffer.c +0
-3@@ -310,28 +310,19 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)#endif {void *ret; -if (a) - { -struct gc_entry *e;NACK on that. We discovered that there are use cases where "second-level" callers pass NULL, seemingly on purpose to allocate global memory instead of "in the GC".
main(), inopenvpn.c:/* initialize environmental variable store */ c.es = env_set_create (NULL);... which calls into
misc.c:struct
env_set*env_set_create(structgc_arena*gc){ struct env_set *es; ALLOC_OBJ_CLEAR_GC (es, struct env_set, gc); es->list = NULL; es->gc = gc; return es; }Quoted 6 lines
... and boom,
assert()fail.Adriaan saw the crash ("my nice OpenBSD test run!!!") and promised to work on this on the way back in the train.
But should this actually call
gc_malloc()in this case?gc_mallocis for things which are supposed to be tackled by the garbage collector.Things aren't too easy here - but I'd rather see us cleaning up this instead of making
gc_malloc()vague in its purpose.$ git grep env_set_create init.c: c->c2.es = env_set_create (NULL); manage.c: struct env_set *es = env_set_create (&gc); misc.c:env_set_create (struct gc_arena *gc) misc.h:struct env_set *env_set_create (struct gc_arena *gc); multi.c: es = env_set_create (&gc); openvpn.c: c.es = env_set_create (NULL);
Quoted 2 lines
There are two places where
env_set_create()is called with NULL. Let's rather see if we can provide agc_arenapointer those places instead. Or do something which is more clear in regards to memory allocation inenv_set_create().
I agree with Gert:
I spent most of my train journey yesterday figuring out what the next assert failure/segfault was , caused by this buffer.c change; env_set_create is one, log_history_add was also giving me problems, etc etc. With the 2.2.2 version of gc_malloc my Elliptic Curve patch works like a charm (in the git version of OpenVPN).
The idea behind this change is good, but it needs a LOT of testing before we can proceed.
cheers,
JJK
PS was great fun to meet you guys yesterday!
Re: [Openvpn-devel] [PATCH 2/2] Removed support for calling gc_malloc with a NULL gc_arena struct
Quoted 11 lines
-----Original Message-----
From: Jan Just Keijser [mailto:[email protected]...]I agree with Gert:
I spent most of my train journey yesterday figuring out what the next assert failure/segfault was , caused by thisbuffer.cchange;env_set_createis one,log_history_addwas also giving me problems, etc etc.
With the 2.2.2 version ofgc_mallocmy Elliptic Curve patch works like a charm (in the git version of OpenVPN).
Quoted 3 lines
The idea behind this change is good, but it needs a LOT of testing before we can proceed.
I agree. Gc_malloc is very low in the stack, and there are a lot of potential places that this could go wrong. Hunting them down is going to be a challenge. I'll see what I can do in the next few evenings. If I see it spiralling out of control I'll let you know.
Adriaan
Quoted 5 lines · Adriaan de Jong
Signed-off-by Adriaan de Jong<[email protected]...>--- buffer.h | 4 +--- error.h | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-)
ACK to both patches. Applied to master on -testing and -stable.
commit bee92b479414d12035b0422f81ac5fcfe14fa645
Author: Adriaan de Jong <[email protected]...> Date: Sun Feb 5 12:51:25 2012 +0100
Removed support for calling gc_malloc with a NULL gc_arena struct
commit 2b7deeb6632582fcfb23492e77bb09395d1be4ca
Author: Adriaan de Jong <[email protected]...> Date: Sun Feb 5 12:51:24 2012 +0100
Moved out of memory prototype to error.h, as the definition is inerror.c
Signed-off-by: Adriaan de Jong <[email protected]...> Acked-by: David Sommerseth <[email protected]...> Signed-off-by: David Sommerseth <[email protected]...>
kind regards,
David Sommerseth