Skip to contentSkip to conversation

RFC: Move memory allocations from malloc() to calloc()

PATCH New David Sommerseth 1 participant 5 messages Nov 21, 2013

lore
Share & tools
lore
#0 lore raw

cover RFC: Move memory allocations from malloc() to calloc()

From: David Sommerseth <[email protected]...>

Hi,

This might be seen as controversial for some, but my intension here is just to clean up and simplify the code base a little bit by reducing the memory/buffer allocation API.

The reason for doing a move from malloc() to calloc() is to first of all simplify the memory management (buffer) code somewhat. As with calloc() you will always get a cleared memory region by default, which means much of the current API-set for memory management can be somewhat reduced. Currently we have separate functions and macros, one set which clears the memory and another one which does not.

Some even claim that calloc() has a smaller overhead than doing a malloc() call + memset(). If this truly is true, then OpenVPN may even perform slightly better. But this is most likely also tightly connected to how the kernel and the libc library handles memory allocations.

And the last reason, probably the most important one in my eyes, is that when you work by default on cleared memory regions, buffer overruns are harder to accomplish. As long as you stay inside the allocated memory region, you cannot trigger overrun issues due to missing NULL termination. The memory region contains by default only NULLs.

I've split this patch set into several pieces to hopefully eaiser see the bigger picture.

These patches needs to be tested a bit more, but it compiles well on Fedora 19 (with a compiler which can by default complain a lot). Also basic client testing seems to work fine too. The overall behaviour is not expected to change, excpet perhaps a slight performance boost if we're lucky.

kind regards,

David Sommerseth

David Sommerseth (4):
Move over to calloc() in gc_malloc()
Change from malloc() to calloc() where it can be beneficial Move ALLOC_OBJ() macro to use calloc()
Merge the rest of ALLOC_*_CLEAR*() macros into ALLOC_*()

 src/openvpn/base64.c              |  2 +-
 src/openvpn/buffer.c              | 34 ++++++++++++++++-----------------
 src/openvpn/buffer.h              | 40 +++++++++------------------------------
 src/openvpn/circ_list.h           |  2 +-
 src/openvpn/clinat.c              |  2 +-
 src/openvpn/comp.c                |  6 +++---
 src/openvpn/console.c             |  2 +-
 src/openvpn/crypto.c              |  2 +-
 src/openvpn/error.c               |  4 ++--
 src/openvpn/event.c               | 20 ++++++++++----------
 src/openvpn/fragment.c            |  2 +-
 src/openvpn/init.c                |  8 ++++----
 src/openvpn/list.c                |  2 +-
 src/openvpn/manage.c              |  8 ++++----
 src/openvpn/mbuf.c                |  2 +-
 src/openvpn/misc.c                | 32 +++++++++++++++----------------
 src/openvpn/mroute.c              |  2 +-
 src/openvpn/mtcp.c                |  2 +-
 src/openvpn/mtu.c                 |  2 +-
 src/openvpn/multi.c               |  2 +-
 src/openvpn/openvpn.c             |  2 +-
 src/openvpn/options.c             | 20 ++++++++++----------
 src/openvpn/pf.c                  |  8 ++++----
 src/openvpn/plugin.c              | 10 +++++-----
 src/openvpn/pool.c                | 10 +++++-----
 src/openvpn/proxy.c               |  6 +++---
 src/openvpn/ps.c                  | 12 ++++++------
 src/openvpn/push.c                |  2 +-
 src/openvpn/route.c               | 16 ++++++++--------
 src/openvpn/schedule.c            |  4 ++--
 src/openvpn/socket.c              |  2 +-
 src/openvpn/socks.c               |  2 +-
 src/openvpn/ssl.c                 | 20 ++++++++++----------
 src/openvpn/ssl_openssl.c         |  2 +-
 src/openvpn/ssl_polarssl.c        | 24 +++++++++++------------
 src/openvpn/ssl_verify.c          |  6 +++---
 src/openvpn/ssl_verify_openssl.c  | 12 ++++++------
 src/openvpn/ssl_verify_polarssl.c |  4 ++--
 src/openvpn/status.c              |  2 +-
 src/openvpn/tun.c                 | 14 +++++++-------
 src/openvpn/win32.c               |  6 +++---
 41 files changed, 168 insertions(+), 192 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/4 Move over to calloc() in gc_malloc()

From: David Sommerseth <[email protected]...>

Instead of using malloc(), use calloc() which will always provide a cleared memory region. Depending on the kernel and libc implementation, this can in many cases give a better performance.

Another advantage of having a cleared memory is that it can in many cases prevent buffer overruns, due to improper NULL termination.

In addition, this simplifies the gc_malloc() API by removing an argument which is no longer needed.

---
 src/openvpn/buffer.c              | 22 ++++++++++------------
 src/openvpn/buffer.h              | 16 ++++++++--------
 src/openvpn/error.c               |  4 ++--
 src/openvpn/misc.c                | 10 +++++-----
 src/openvpn/mtu.c                 |  2 +-
 src/openvpn/options.c             | 12 ++++++------
 src/openvpn/plugin.c              |  2 +-
 src/openvpn/proxy.c               |  2 +-
 src/openvpn/route.c               |  8 ++++----
 src/openvpn/ssl.c                 |  2 +-
 src/openvpn/ssl_verify_openssl.c  |  6 +++---
 src/openvpn/ssl_verify_polarssl.c |  4 ++--
 src/openvpn/tun.c                 |  8 ++++----
 src/openvpn/win32.c               |  4 ++--
 14 files changed, 50 insertions(+), 52 deletions(-)
src/openvpn/buffer.c +10 -12
index fb3b52d..096d1fa 100644
@@ -92,9 +92,9 @@ alloc_buf_gc (size_t size, struct gc_arena *gc)
   buf.offset = 0;
   buf.len = 0;
 #ifdef DMALLOC
-  buf.data = (uint8_t *) gc_malloc_debug (size, false, gc, file, line);
+  buf.data = (uint8_t *) gc_malloc_debug (size, gc, file, line);
 #else
-  buf.data = (uint8_t *) gc_malloc (size, false, gc);
+  buf.data = (uint8_t *) gc_malloc (size, gc);
 #endif
   if (size)
     *buf.data = 0;
@@ -321,9 +321,9 @@ buf_write_string_file (const struct buffer *buf, const char *filename, int fd)
 
 void *
 #ifdef DMALLOC
-gc_malloc_debug (size_t size, bool clear, struct gc_arena *a, const char *file, int line)
+gc_malloc_debug (size_t size, struct gc_arena *a, const char *file, int line)
 #else
-gc_malloc (size_t size, bool clear, struct gc_arena *a)
+gc_malloc (size_t size, struct gc_arena *a)
 #endif
 {
   void *ret;
@@ -332,8 +332,9 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)
       struct gc_entry *e;
 #ifdef DMALLOC
       e = (struct gc_entry *) openvpn_dmalloc (file, line, size + sizeof (struct gc_entry));
+      memset(e, 0, size + sizeof (struct gc_entry));
 #else
-      e = (struct gc_entry *) malloc (size + sizeof (struct gc_entry));
+      e = (struct gc_entry *) calloc (1, size + sizeof (struct gc_entry));
 #endif
       check_malloc_return (e);
       ret = (char *) e + sizeof (struct gc_entry);
@@ -344,15 +345,12 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a)
     {
 #ifdef DMALLOC
       ret = openvpn_dmalloc (file, line, size);
+      memset(ret, 0, size + sizeof (struct gc_entry));
 #else
-      ret = malloc (size);
+      ret = calloc (1, size);
 #endif
       check_malloc_return (ret);
     }
-#ifndef ZERO_BUFFER_ON_ALLOC
-  if (clear)
-#endif
-    memset (ret, 0, size);
   return ret;
 }
 
@@ -543,9 +541,9 @@ string_alloc (const char *str, struct gc_arena *gc)
 
       if (gc) {
 #ifdef DMALLOC
-        ret = (char *) gc_malloc_debug (n, false, gc, file, line);
+        ret = (char *) gc_malloc_debug (n, gc, file, line);
 #else
-        ret = (char *) gc_malloc (n, false, gc);
+        ret = (char *) gc_malloc (n, gc);
 #endif
       } else {
         /* If there are no garbage collector available, it's expected
src/openvpn/buffer.h +8 -8
index 93efb09..bbf715a 100644
@@ -141,14 +141,14 @@ void buf_size_error (const size_t size);
 #define alloc_buf(size)               alloc_buf_debug (size, __FILE__, __LINE__)
 #define alloc_buf_gc(size, gc)        alloc_buf_gc_debug (size, gc, __FILE__, __LINE__);
 #define clone_buf(buf)                clone_buf_debug (buf, __FILE__, __LINE__);
-#define gc_malloc(size, clear, arena) gc_malloc_debug (size, clear, arena, __FILE__, __LINE__)
+#define gc_malloc(size, arena)        gc_malloc_debug (size, arena, __FILE__, __LINE__)
 #define string_alloc(str, gc)         string_alloc_debug (str, gc, __FILE__, __LINE__)
 #define string_alloc_buf(str, gc)     string_alloc_buf_debug (str, gc, __FILE__, __LINE__)
 
 struct buffer alloc_buf_debug (size_t size, const char *file, int line);
 struct buffer alloc_buf_gc_debug (size_t size, struct gc_arena *gc, const char *file, int line);
 struct buffer clone_buf_debug (const struct buffer* buf, const char *file, int line);
-void *gc_malloc_debug (size_t size, bool clear, struct gc_arena *a, const char *file, int line);
+void *gc_malloc_debug (size_t size, struct gc_arena *a, const char *file, int line);
 char *string_alloc_debug (const char *str, struct gc_arena *gc, const char *file, int line);
 struct buffer string_alloc_buf_debug (const char *str, struct gc_arena *gc, const char *file, int line);
 
@@ -157,7 +157,7 @@ struct buffer string_alloc_buf_debug (const char *str, struct gc_arena *gc, cons
 struct buffer alloc_buf (size_t size);
 struct buffer alloc_buf_gc (size_t size, struct gc_arena *gc); /* allocate buffer with garbage collection */
 struct buffer clone_buf (const struct buffer* buf);
-void *gc_malloc (size_t size, bool clear, struct gc_arena *a);
+void *gc_malloc (size_t size, struct gc_arena *a);
 char *string_alloc (const char *str, struct gc_arena *gc);
 struct buffer string_alloc_buf (const char *str, struct gc_arena *gc);
 
@@ -840,7 +840,7 @@ gc_reset (struct gc_arena *a)
 
 #define ALLOC_ARRAY_GC(dptr, type, n, gc) \
 { \
-  (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (type), (n), 0), false, (gc)); \
+  (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (type), (n), 0), (gc)); \
 }
 
 #define ALLOC_ARRAY_CLEAR(dptr, type, n) \
@@ -851,22 +851,22 @@ gc_reset (struct gc_arena *a)
 
 #define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc) \
 { \
-  (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (type), (n), 0), true, (gc)); \
+  (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (type), (n), 0), (gc)); \
 }
 
 #define ALLOC_VAR_ARRAY_CLEAR_GC(dptr, type, atype, n, gc)	\
 { \
-  (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (atype), (n), sizeof (type)), true, (gc)); \
+  (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (atype), (n), sizeof (type)), (gc)); \
 }
 
 #define ALLOC_OBJ_GC(dptr, type, gc) \
 { \
-  (dptr) = (type *) gc_malloc (sizeof (type), false, (gc)); \
+  (dptr) = (type *) gc_malloc (sizeof (type), (gc)); \
 }
 
 #define ALLOC_OBJ_CLEAR_GC(dptr, type, gc) \
 { \
-  (dptr) = (type *) gc_malloc (sizeof (type), true, (gc)); \
+  (dptr) = (type *) gc_malloc (sizeof (type), (gc)); \
 }
 
 static inline void
src/openvpn/error.c +2 -2
index 6848425..dc9d855 100644
@@ -241,8 +241,8 @@ void x_msg_va (const unsigned int flags, const char *format, va_list arglist)
 
   gc_init (&gc);
 
-  m1 = (char *) gc_malloc (ERR_BUF_SIZE, false, &gc);
-  m2 = (char *) gc_malloc (ERR_BUF_SIZE, false, &gc);
+  m1 = (char *) gc_malloc (ERR_BUF_SIZE, &gc);
+  m2 = (char *) gc_malloc (ERR_BUF_SIZE, &gc);
 
   vsnprintf (m1, ERR_BUF_SIZE, format, arglist);
   m1[ERR_BUF_SIZE - 1] = 0; /* windows vsnprintf needs this */
src/openvpn/misc.c +5 -5
index 4688444..1175ff4 100644
@@ -1095,7 +1095,7 @@ get_user_pass_cr (struct user_pass *up,
 	      struct auth_challenge_info *ac = get_auth_challenge (auth_challenge, &gc);
 	      if (ac)
 		{
-		  char *response = (char *) gc_malloc (USER_PASS_LEN, false, &gc);
+		  char *response = (char *) gc_malloc (USER_PASS_LEN, &gc);
 		  struct buffer packed_resp;
 
 		  buf_set_write (&packed_resp, (uint8_t*)up->password, USER_PASS_LEN);
@@ -1133,7 +1133,7 @@ get_user_pass_cr (struct user_pass *up,
 #ifdef ENABLE_CLIENT_CR
 	      if (auth_challenge && (flags & GET_USER_PASS_STATIC_CHALLENGE))
 		{
-		  char *response = (char *) gc_malloc (USER_PASS_LEN, false, &gc);
+		  char *response = (char *) gc_malloc (USER_PASS_LEN, &gc);
 		  struct buffer packed_resp;
 		  char *pw64=NULL, *resp64=NULL;
 
@@ -1228,7 +1228,7 @@ get_auth_challenge (const char *auth_challenge, struct gc_arena *gc)
     {
       struct auth_challenge_info *ac;
       const int len = strlen (auth_challenge);
-      char *work = (char *) gc_malloc (len+1, false, gc);
+      char *work = (char *) gc_malloc (len+1, gc);
       char *cp;
 
       struct buffer b;
@@ -1262,7 +1262,7 @@ get_auth_challenge (const char *auth_challenge, struct gc_arena *gc)
       /* parse user name */
       if (!buf_parse(&b, ':', work, len))
 	return NULL;
-      ac->user = (char *) gc_malloc (strlen(work)+1, true, gc);
+      ac->user = (char *) gc_malloc (strlen(work)+1, gc);
       openvpn_base64_decode(work, (void*)ac->user, -1);
 
       /* parse challenge text */
@@ -1999,7 +1999,7 @@ argv_test (void)
 const char *
 sanitize_control_message(const char *src, struct gc_arena *gc)
 {
-  char *ret = gc_malloc (strlen(src)+1, false, gc);
+  char *ret = gc_malloc (strlen(src)+1, gc);
   char *dest = ret;
   bool redact = false;
   int skip = 0;
src/openvpn/mtu.c +1 -1
index 13f3f6c..52854d4 100644
@@ -206,7 +206,7 @@ format_extended_socket_error (int fd, int *mtu, struct gc_arena *gc)
   struct sock_extended_err *e;
   struct sockaddr_in addr;
   struct buffer out = alloc_buf_gc (256, gc);
-  char *cbuf = (char *) gc_malloc (256, false, gc);
+  char *cbuf = (char *) gc_malloc (256, gc);
 
   *mtu = 0;
 
src/openvpn/options.c +6 -6
index e925397..81e9a6e 100644
@@ -1040,7 +1040,7 @@ static bool ipv6_addr_safe_hexplusbits( const char * ipv6_prefix_spec )
 static char *
 string_substitute (const char *src, int from, int to, struct gc_arena *gc)
 {
-  char *ret = (char *) gc_malloc (strlen (src) + 1, true, gc);
+  char *ret = (char *) gc_malloc (strlen (src) + 1, gc);
   char *dest = ret;
   char c;
 
@@ -1061,7 +1061,7 @@ parse_hash_fingerprint(const char *str, int nbytes, int msglevel, struct gc_aren
 {
   int i;
   const char *cp = str;
-  uint8_t *ret = (uint8_t *) gc_malloc (nbytes, true, gc);
+  uint8_t *ret = (uint8_t *) gc_malloc (nbytes, gc);
   char term = 1;
   int byte;
   char bs[3];
@@ -3089,7 +3089,7 @@ options_warning_extract_parm1 (const char *option_string,
 {
   struct gc_arena gc = gc_new ();
   struct buffer b = string_alloc_buf (option_string, &gc);
-  char *p = gc_malloc (OPTION_PARM_SIZE, false, &gc);
+  char *p = gc_malloc (OPTION_PARM_SIZE, &gc);
   const char *ret;
   
   buf_parse (&b, ' ', p, OPTION_PARM_SIZE);
@@ -3121,7 +3121,7 @@ options_warning_safe_scan2 (const int msglevel,
       struct gc_arena gc = gc_new ();
       struct buffer b2 = *b2_src;
       const char *p1_prefix = options_warning_extract_parm1 (p1, &gc);
-      char *p2 = gc_malloc (OPTION_PARM_SIZE, false, &gc);
+      char *p2 = gc_malloc (OPTION_PARM_SIZE, &gc);
 
       while (buf_parse (&b2, delim, p2, OPTION_PARM_SIZE))
 	{
@@ -3168,7 +3168,7 @@ options_warning_safe_scan1 (const int msglevel,
 {
   struct gc_arena gc = gc_new ();
   struct buffer b = *b1_src;
-  char *p = gc_malloc (OPTION_PARM_SIZE, true, &gc);
+  char *p = gc_malloc (OPTION_PARM_SIZE, &gc);
 
   while (buf_parse (&b, delim, p, OPTION_PARM_SIZE))
       options_warning_safe_scan2 (msglevel, delim, report_inconsistent, p, b2_src, b1_name, b2_name);
@@ -3566,7 +3566,7 @@ parse_line (const char *line,
 	  if (state == STATE_DONE)
 	    {
 	      /* ASSERT (parm_len > 0); */
-	      p[ret] = gc_malloc (parm_len + 1, true, gc);
+	      p[ret] = gc_malloc (parm_len + 1, gc);
 	      memcpy (p[ret], parm, parm_len);
 	      p[ret][parm_len] = '\0';
 	      state = STATE_INITIAL;
src/openvpn/plugin.c +1 -1
index 0948f23..71ad0b6 100644
@@ -325,7 +325,7 @@ plugin_vlog (openvpn_plugin_log_flags_t flags, const char *name, const char *for
       msg_flags |= M_NOIPREFIX;
 
       gc_init (&gc);
-      msg_fmt = gc_malloc (ERR_BUF_SIZE, false, &gc);
+      msg_fmt = gc_malloc (ERR_BUF_SIZE, &gc);
       openvpn_snprintf (msg_fmt, ERR_BUF_SIZE, "PLUGIN %s: %s", name, format);
       x_msg_va (msg_flags, msg_fmt, arglist);
 
src/openvpn/proxy.c +1 -1
index c3496e2..9ef1b8f 100644
@@ -784,7 +784,7 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
 	      if (opaque)
 		{
 		  const int len = strlen(opaque)+16;
-		  opaque_kv = gc_malloc(len, false, &gc);
+		  opaque_kv = gc_malloc(len, &gc);
 		  openvpn_snprintf (opaque_kv, len, ", opaque=\"%s\"", opaque);
 		}
 
src/openvpn/route.c +4 -4
index 19b4bfe..37ef096 100644
@@ -113,7 +113,7 @@ struct route_option_list *
 clone_route_option_list (const struct route_option_list *src, struct gc_arena *a)
 {
   const size_t rl_size = array_mult_safe (sizeof(struct route_option), src->capacity, sizeof(struct route_option_list));
-  struct route_option_list *ret = gc_malloc (rl_size, false, a);
+  struct route_option_list *ret = gc_malloc (rl_size, a);
   memcpy (ret, src, rl_size);
   return ret;
 }
@@ -122,7 +122,7 @@ struct route_ipv6_option_list *
 clone_route_ipv6_option_list (const struct route_ipv6_option_list *src, struct gc_arena *a)
 {
   const size_t rl_size = array_mult_safe (sizeof(struct route_ipv6_option), src->capacity, sizeof(struct route_ipv6_option_list));
-  struct route_ipv6_option_list *ret = gc_malloc (rl_size, false, a);
+  struct route_ipv6_option_list *ret = gc_malloc (rl_size, a);
   memcpy (ret, src, rl_size);
   return ret;
 }
@@ -2080,7 +2080,7 @@ get_windows_routing_table (struct gc_arena *gc)
   status = GetIpForwardTable (NULL, &size, TRUE);
   if (status == ERROR_INSUFFICIENT_BUFFER)
     {
-      rt = (PMIB_IPFORWARDTABLE) gc_malloc (size, false, gc);
+      rt = (PMIB_IPFORWARDTABLE) gc_malloc (size, gc);
       status = GetIpForwardTable (rt, &size, TRUE);
       if (status != NO_ERROR)
 	{
@@ -2925,7 +2925,7 @@ get_default_gateway (struct route_gateway_info *rgi)
       const int bufsize = 4096;
       char *buffer;
 
-      buffer = (char *) gc_malloc (bufsize, true, &gc);
+      buffer = (char *) gc_malloc (bufsize, &gc);
       sockfd = socket(AF_INET, SOCK_DGRAM, 0);
       if (sockfd < 0)
 	{
src/openvpn/ssl.c +1 -1
index 4203fc5..35e5bfb 100644
@@ -1429,7 +1429,7 @@ tls1_PRF(uint8_t *label,
   const uint8_t *S1,*S2;
   uint8_t *out2;
 
-  out2 = (uint8_t *) gc_malloc (olen, false, &gc);
+  out2 = (uint8_t *) gc_malloc (olen, &gc);
 
   len=slen/2;
   S1=sec;
src/openvpn/ssl_verify_openssl.c +3 -3
index 658f5f3..105329d 100644
@@ -241,7 +241,7 @@ x509_get_serial (openvpn_x509_cert_t *cert, struct gc_arena *gc)
 unsigned char *
 x509_get_sha1_hash (X509 *cert, struct gc_arena *gc)
 {
-  char *hash = gc_malloc(SHA_DIGEST_LENGTH, false, gc);
+  char *hash = gc_malloc(SHA_DIGEST_LENGTH, gc);
   memcpy(hash, cert->sha1_hash, SHA_DIGEST_LENGTH);
   return hash;
 }
@@ -260,7 +260,7 @@ x509_get_subject (X509 *cert, struct gc_arena *gc)
    */
   if (compat_flag (COMPAT_FLAG_QUERY | COMPAT_NAMES))
     {
-      subject = gc_malloc (256, false, gc);
+      subject = gc_malloc (256, gc);
       X509_NAME_oneline (X509_get_subject_name (cert), subject, 256);
       subject[255] = '\0';
       return subject;
@@ -280,7 +280,7 @@ x509_get_subject (X509 *cert, struct gc_arena *gc)
   BIO_get_mem_ptr (subject_bio, &subject_mem);
 
   maxlen = subject_mem->length + 1;
-  subject = gc_malloc (maxlen, false, gc);
+  subject = gc_malloc (maxlen, gc);
 
   memcpy (subject, subject_mem->data, maxlen);
   subject[maxlen - 1] = '\0';
src/openvpn/ssl_verify_polarssl.c +2 -2
index 5db4f02..e267634 100644
@@ -130,7 +130,7 @@ x509_get_serial (x509_cert *cert, struct gc_arena *gc)
   char *buf = NULL;
   size_t len = cert->serial.len * 3 + 1;
 
-  buf = gc_malloc(len, true, gc);
+  buf = gc_malloc(len, gc);
 
   if(x509parse_serial_gets(buf, len-1, &cert->serial) < 0)
     buf = NULL;
@@ -141,7 +141,7 @@ x509_get_serial (x509_cert *cert, struct gc_arena *gc)
 unsigned char *
 x509_get_sha1_hash (x509_cert *cert, struct gc_arena *gc)
 {
-  unsigned char *sha1_hash = gc_malloc(SHA_DIGEST_LENGTH, false, gc);
+  unsigned char *sha1_hash = gc_malloc(SHA_DIGEST_LENGTH, gc);
   sha1(cert->tbs.p, cert->tbs.len, sha1_hash);
   return sha1_hash;
 }
src/openvpn/tun.c +4 -4
index 9f53b23..ea2d102 100644
@@ -3196,7 +3196,7 @@ get_panel_reg (struct gc_arena *gc)
 
 	      ALLOC_OBJ_CLEAR_GC (reg, struct panel_reg, gc);
               n = WideCharToMultiByte (CP_UTF8, 0, name_data, -1, NULL, 0, NULL, NULL);
-              name = gc_malloc (n, false, gc);
+              name = gc_malloc (n, gc);
               WideCharToMultiByte (CP_UTF8, 0, name_data, -1, name, n, NULL, NULL);
               reg->name = name;
 	      reg->guid = string_alloc (enum_name, gc);
@@ -3535,7 +3535,7 @@ get_adapter_info_list (struct gc_arena *gc)
     }
   else
     {
-      pi = (PIP_ADAPTER_INFO) gc_malloc (size, false, gc);
+      pi = (PIP_ADAPTER_INFO) gc_malloc (size, gc);
       if ((status = GetAdaptersInfo (pi, &size)) == NO_ERROR)
 	return pi;
       else
@@ -3565,7 +3565,7 @@ get_per_adapter_info (const DWORD index, struct gc_arena *gc)
 	}
       else
 	{
-	  pi = (PIP_PER_ADAPTER_INFO) gc_malloc (size, false, gc);
+	  pi = (PIP_PER_ADAPTER_INFO) gc_malloc (size, gc);
 	  if ((status = GetPerAdapterInfo ((ULONG)index, pi, &size)) == ERROR_SUCCESS)
 	    return pi;
 	  else
@@ -3594,7 +3594,7 @@ get_interface_info_list (struct gc_arena *gc)
     }
   else
     {
-      ii = (PIP_INTERFACE_INFO) gc_malloc (size, false, gc);
+      ii = (PIP_INTERFACE_INFO) gc_malloc (size, gc);
       if ((status = GetInterfaceInfo (ii, &size)) == NO_ERROR)
 	return ii;
       else
src/openvpn/win32.c +2 -2
index 022eec5..ce23469 100644
@@ -829,7 +829,7 @@ wide_cmd_line (const struct argv *a, struct gc_arena *gc)
 	maxlen = len;
     }
 
-  work = gc_malloc (maxlen + 1, false, gc);
+  work = gc_malloc (maxlen + 1, gc);
   check_malloc_return (work);
   buf = alloc_buf_gc (nchars, gc);
 
@@ -917,7 +917,7 @@ WCHAR *
 wide_string (const char* utf8, struct gc_arena *gc)
 {
   int n = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
-  WCHAR *ucs16 = gc_malloc (n * sizeof (WCHAR), false, gc);
+  WCHAR *ucs16 = gc_malloc (n * sizeof (WCHAR), gc);
   MultiByteToWideChar (CP_UTF8, 0, utf8, -1, ucs16, n);
   return ucs16;
 }
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/4 Change from malloc() to calloc() where it can be beneficial

In reply to David Sommerseth

From: David Sommerseth <[email protected]...>

This is a continuation of the malloc() -> calloc() change started in gc_malloc(). This is simply to to small steps to ensure memory allocations are cleared and in a sane state.

Not all places should make use of calloc() as they can benefit from having some randomness around itself if the complete buffer isn't used. This goes particular for the crypto and PRNG functions.

---
 src/openvpn/base64.c             | 2 +-
 src/openvpn/buffer.c             | 6 +++---
 src/openvpn/circ_list.h          | 2 +-
 src/openvpn/console.c            | 2 +-
 src/openvpn/crypto.c             | 2 +-
 src/openvpn/manage.c             | 2 +-
 src/openvpn/misc.c               | 8 ++++----
 src/openvpn/openvpn.c            | 2 +-
 src/openvpn/ps.c                 | 6 +++---
 src/openvpn/ssl.c                | 2 +-
 src/openvpn/ssl_verify_openssl.c | 4 ++--
 src/openvpn/tun.c                | 2 +-
 src/openvpn/win32.c              | 2 +-
 13 files changed, 21 insertions(+), 21 deletions(-)
src/openvpn/base64.c +1 -1
index bb89aae..a35e36d 100644
@@ -62,7 +62,7 @@ openvpn_base64_encode(const void *data, int size, char **str)
 
     if (size < 0)
 	return -1;
-    p = s = (char *) malloc(size * 4 / 3 + 4);
+    p = s = (char *) calloc(1, size * 4 / 3 + 4);
     if (p == NULL)
 	return -1;
     q = (const unsigned char *) data;
src/openvpn/buffer.c +3 -3
index 096d1fa..cd8d397 100644
@@ -115,7 +115,7 @@ clone_buf (const struct buffer* buf)
 #ifdef DMALLOC
   ret.data = (uint8_t *) openvpn_dmalloc (file, line, buf->capacity);
 #else
-  ret.data = (uint8_t *) malloc (buf->capacity);
+  ret.data = (uint8_t *) calloc (1, buf->capacity);
 #endif
   check_malloc_return (ret.data);
   memcpy (BPTR (&ret), BPTR (buf), BLEN (buf));
@@ -1048,7 +1048,7 @@ buffer_list_aggregate (struct buffer_list *bl, const size_t max)
 	  struct buffer_entry *e = bl->head, *f;
 
 	  ALLOC_OBJ_CLEAR (f, struct buffer_entry);
-	  f->buf.data = malloc (size);
+	  f->buf.data = calloc (1, size);
 	  check_malloc_return (f->buf.data);
 	  f->buf.capacity = size;
 	  for (i = 0; e && i < count; ++i)
@@ -1102,7 +1102,7 @@ buffer_list_file (const char *fn, int max_line_len)
 
   if (fp)
     {
-      char *line = (char *) malloc (max_line_len);
+      char *line = (char *) calloc (1, max_line_len);
       if (line)
 	{
 	  bl = buffer_list_new (0);
src/openvpn/circ_list.h +1 -1
index 583701a..ba6bb9d 100644
@@ -65,7 +65,7 @@ struct name { \
 #define CIRC_LIST_ALLOC(dest, list_type, size) \
 { \
   const int so = sizeof (list_type) + sizeof ((dest)->x_list[0]) * (size); \
-  (dest) = (list_type *) malloc (so); \
+  (dest) = (list_type *) calloc (1, so);                               \
   check_malloc_return (dest); \
   memset ((dest), 0, so); \
   (dest)->x_cap = size; \
src/openvpn/console.c +1 -1
index afda8ca..d94dff9 100644
@@ -86,7 +86,7 @@ get_console_input_win32 (const char *prompt, const bool echo, char *input, const
 
       if (is_console)
         {
-          winput = malloc (capacity * sizeof (WCHAR));
+          winput = calloc (1, capacity * sizeof (WCHAR));
           if (winput == NULL)
             return false;
 
src/openvpn/crypto.c +1 -1
index c4c356d..3507b53 100644
@@ -1334,7 +1334,7 @@ prng_init (const char *md_name, const int nonce_secret_len_parm)
       {
 	const int size = md_kt_size(nonce_md) + nonce_secret_len;
 	dmsg (D_CRYPTO_DEBUG, "PRNG init md=%s size=%d", md_kt_name(nonce_md), size);
-	nonce_data = (uint8_t*) malloc (size);
+	nonce_data = (uint8_t*) malloc (size);  /* Avoid using cleared memory when handling PRNG data */
 	check_malloc_return (nonce_data);
 	prng_reset_nonce();
       }
src/openvpn/manage.c +1 -1
index 74de1e1..9c40fbe 100644
@@ -3105,7 +3105,7 @@ management_query_rsa_sig (struct management *man,
 	  buf = buffer_list_peek (mc->ext_key_input);
 	  if (buf && BLEN(buf) > 0)
 	    {
-	      ret = (char *) malloc(BLEN(buf)+1);
+	      ret = (char *) calloc(1, BLEN(buf)+1);
 	      check_malloc_return(ret);
 	      memcpy(ret, buf->data, BLEN(buf));
 	      ret[BLEN(buf)] = '\0';
src/openvpn/misc.c +4 -4
index 1175ff4..2132649 100644
@@ -1619,7 +1619,7 @@ argv_system_str_append (struct argv *a, const char *str, const bool enquote)
 	l += 2; /* space for two quotes */
 
       /* build new system_str */
-      newstr = (char *) malloc (l);
+      newstr = (char *) calloc (1, l);
       newstr[0] = '\0';
       check_malloc_return (newstr);
       if (a->system_str)
@@ -1738,7 +1738,7 @@ argv_term (const char **f)
     {
       char *ret;
       ASSERT (termlen > 0);
-      ret = malloc (termlen + 1);
+      ret = calloc (1, termlen + 1);
       check_malloc_return (ret);
       memcpy (ret, term, termlen);
       ret[termlen] = '\0';
@@ -1866,7 +1866,7 @@ argv_printf_arglist (struct argv *a, const char *format, const unsigned int flag
 
 	      {
 		const size_t len = strlen(s) + strlen(numstr) + 2;
-		char *combined = (char *) malloc (len);
+		char *combined = (char *) calloc (1, len);
 		check_malloc_return (combined);
 
 		strcpy (combined, s);
@@ -1885,7 +1885,7 @@ argv_printf_arglist (struct argv *a, const char *format, const unsigned int flag
 
 	      if (!s1) s1 = "";
 	      if (!s2) s2 = "";
-	      combined = (char *) malloc (strlen(s1) + strlen(s2) + 1);
+	      combined = (char *) calloc (1, strlen(s1) + strlen(s2) + 1);
 	      check_malloc_return (combined);
 	      strcpy (combined, s1);
 	      strcat (combined, s2);
src/openvpn/openvpn.c +1 -1
index 5125eae..60b1fb7 100644
@@ -304,7 +304,7 @@ wmain (int argc, wchar_t *wargv[]) {
   for (i = 0; i < argc; i++)
     {
       int n = WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
-      argv[i] = malloc (n);
+      argv[i] = calloc (1, n);
       WideCharToMultiByte (CP_UTF8, 0, wargv[i], -1, argv[i], n, NULL, NULL);
     }
 
src/openvpn/ps.c +3 -3
index 6495dc7..f6b5212 100644
@@ -212,7 +212,7 @@ port_share_sendmsg (const socket_descriptor_t sd,
       mesg.msg_iov = iov;
 
       mesg.msg_controllen = cmsg_size ();
-      mesg.msg_control = (char *) malloc (mesg.msg_controllen);
+      mesg.msg_control = (char *) calloc (1, mesg.msg_controllen);
       check_malloc_return (mesg.msg_control);
       mesg.msg_flags = 0;
 
@@ -333,7 +333,7 @@ journal_add (const char *journal_dir, struct proxy_connection *pc, struct proxy_
       const char *f = print_sockaddr_ex (&from, ":", PS_SHOW_PORT, &gc);
       const char *t = print_sockaddr_ex (&to, ":", PS_SHOW_PORT, &gc);
       fnlen =  strlen(journal_dir) + strlen(t) + 2;
-      jfn = (char *) malloc(fnlen);
+      jfn = (char *) calloc(1, fnlen);
       check_malloc_return (jfn);
       openvpn_snprintf (jfn, fnlen, "%s/%s", journal_dir, t);
       dmsg (D_PS_PROXY_DEBUG, "PORT SHARE PROXY: client origin %s -> %s", jfn, f);
@@ -508,7 +508,7 @@ control_message_from_parent (const socket_descriptor_t sd_control,
   mesg.msg_iovlen = 2;
 
   mesg.msg_controllen = cmsg_size ();
-  mesg.msg_control = (char *) malloc (mesg.msg_controllen);
+  mesg.msg_control = (char *) calloc (1, mesg.msg_controllen);
   check_malloc_return (mesg.msg_control);
   mesg.msg_flags = 0;
 
src/openvpn/ssl.c +1 -1
index 35e5bfb..7ceb79b 100644
@@ -1719,7 +1719,7 @@ read_string_alloc (struct buffer *buf)
 
   if (len < 1)
     return NULL;
-  str = (char *) malloc(len);
+  str = (char *) calloc(1, len);
   check_malloc_return(str);
   if (!buf_read (buf, str, len))
     {
src/openvpn/ssl_verify_openssl.c +2 -2
index 105329d..176669f 100644
@@ -326,7 +326,7 @@ do_setenv_x509 (struct env_set *es, const char *name, char *value, int depth)
   string_mod (value, CC_ANY, CC_CRLF, '?');
   msg (D_X509_ATTR, "X509 ATTRIBUTE name='%s' value='%s' depth=%d", name, value, depth);
   name_expand_size = 64 + strlen (name);
-  name_expand = (char *) malloc (name_expand_size);
+  name_expand = (char *) calloc (1, name_expand_size);
   check_malloc_return (name_expand);
   openvpn_snprintf (name_expand, name_expand_size, "X509_%d_%s", depth, name);
   setenv_str (es, name_expand, value);
@@ -432,7 +432,7 @@ x509_setenv (struct env_set *es, int cert_depth, openvpn_x509_cert_t *peer_cert)
       if (ASN1_STRING_to_UTF8 (&buf, val) <= 0)
 	continue;
       name_expand_size = 64 + strlen (objbuf);
-      name_expand = (char *) malloc (name_expand_size);
+      name_expand = (char *) calloc (1, name_expand_size);
       check_malloc_return (name_expand);
       openvpn_snprintf (name_expand, name_expand_size, "X509_%d_%s", cert_depth,
 	  objbuf);
src/openvpn/tun.c +1 -1
index ea2d102..de7ccb9 100644
@@ -1945,7 +1945,7 @@ open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tu
     msg (M_ERR, "Can't set PPA %d", ppa);
     }
 
-  tt->actual_name = (char *) malloc (32);
+  tt->actual_name = (char *) calloc (1, 32);
   check_malloc_return (tt->actual_name);
 
   openvpn_snprintf (tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa);
src/openvpn/win32.c +1 -1
index ce23469..63cf34e 100644
@@ -778,7 +778,7 @@ env_block (const struct env_set *es)
 
       nchars += strlen(force_path)+1;
 
-      ret = (char *) malloc (nchars);
+      ret = (char *) calloc (1, nchars);
       check_malloc_return (ret);
 
       p = ret;
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/4 Move ALLOC_OBJ() macro to use calloc()

In reply to David Sommerseth

From: David Sommerseth <[email protected]...>

This continues the malloc() -> calloc() patch set.

This patch also merges ALLOC_OBJ() and ALLOC_OBJ_CLEAR(), as ALLOC_OBJ_CLEAR() would just be a straight wrapper around ALLOC_OBJ()

---
 src/openvpn/buffer.c       |  6 +++---
 src/openvpn/buffer.h       | 10 ++--------
 src/openvpn/comp.c         |  6 +++---
 src/openvpn/event.c        |  8 ++++----
 src/openvpn/fragment.c     |  2 +-
 src/openvpn/init.c         |  2 +-
 src/openvpn/list.c         |  2 +-
 src/openvpn/manage.c       |  4 ++--
 src/openvpn/mbuf.c         |  2 +-
 src/openvpn/mroute.c       |  2 +-
 src/openvpn/mtcp.c         |  2 +-
 src/openvpn/multi.c        |  2 +-
 src/openvpn/pf.c           |  8 ++++----
 src/openvpn/plugin.c       |  6 +++---
 src/openvpn/pool.c         |  4 ++--
 src/openvpn/proxy.c        |  2 +-
 src/openvpn/ps.c           |  6 +++---
 src/openvpn/schedule.c     |  4 ++--
 src/openvpn/socket.c       |  2 +-
 src/openvpn/socks.c        |  2 +-
 src/openvpn/ssl.c          | 10 +++++-----
 src/openvpn/ssl_openssl.c  |  2 +-
 src/openvpn/ssl_polarssl.c | 22 +++++++++++-----------
 src/openvpn/ssl_verify.c   |  4 ++--
 src/openvpn/status.c       |  2 +-
 25 files changed, 58 insertions(+), 64 deletions(-)
src/openvpn/buffer.c +3 -3
index cd8d397..372eb24 100644
@@ -943,7 +943,7 @@ struct buffer_list *
 buffer_list_new (const int max_size)
 {
   struct buffer_list *ret;
-  ALLOC_OBJ_CLEAR (ret, struct buffer_list);
+  ALLOC_OBJ (ret, struct buffer_list);
   ret->max_size = max_size;
   ret->size = 0;
   return ret;
@@ -998,7 +998,7 @@ buffer_list_push_data (struct buffer_list *ol, const uint8_t *data, size_t size)
   struct buffer_entry *e = NULL;
   if (data && (!ol->max_size || ol->size < ol->max_size))
     {
-      ALLOC_OBJ_CLEAR (e, struct buffer_entry);
+      ALLOC_OBJ (e, struct buffer_entry);
 
       ++ol->size;
       if (ol->tail)
@@ -1047,7 +1047,7 @@ buffer_list_aggregate (struct buffer_list *bl, const size_t max)
 	  int i;
 	  struct buffer_entry *e = bl->head, *f;
 
-	  ALLOC_OBJ_CLEAR (f, struct buffer_entry);
+	  ALLOC_OBJ (f, struct buffer_entry);
 	  f->buf.data = calloc (1, size);
 	  check_malloc_return (f->buf.data);
 	  f->buf.capacity = size;
src/openvpn/buffer.h +2 -8
index bbf715a..81d8fea 100644
@@ -824,18 +824,12 @@ gc_reset (struct gc_arena *a)
 
 #define ALLOC_OBJ(dptr, type) \
 { \
-  check_malloc_return ((dptr) = (type *) malloc (sizeof (type))); \
-}
-
-#define ALLOC_OBJ_CLEAR(dptr, type) \
-{ \
-  ALLOC_OBJ (dptr, type); \
-  memset ((dptr), 0, sizeof(type)); \
+  check_malloc_return ((dptr) = (type *) calloc (1, sizeof (type)));     \
 }
 
 #define ALLOC_ARRAY(dptr, type, n) \
 { \
-  check_malloc_return ((dptr) = (type *) malloc (array_mult_safe (sizeof (type), (n), 0))); \
+  check_malloc_return ((dptr) = (type *) calloc (1, array_mult_safe (sizeof (type), (n), 0))); \
 }
 
 #define ALLOC_ARRAY_GC(dptr, type, n, gc) \
src/openvpn/comp.c +3 -3
index 9692257..1507fd2 100644
@@ -45,14 +45,14 @@ comp_init(const struct compress_options *opt)
   switch (opt->alg)
     {
     case COMP_ALG_STUB:
-      ALLOC_OBJ_CLEAR (compctx, struct compress_context);
+      ALLOC_OBJ (compctx, struct compress_context);
       compctx->flags = opt->flags;
       compctx->alg = comp_stub_alg;
       (*compctx->alg.compress_init)(compctx);
       break;
 #ifdef ENABLE_LZO
     case COMP_ALG_LZO:
-      ALLOC_OBJ_CLEAR (compctx, struct compress_context);
+      ALLOC_OBJ (compctx, struct compress_context);
       compctx->flags = opt->flags;
       compctx->alg = lzo_alg;
       (*compctx->alg.compress_init)(compctx);
@@ -60,7 +60,7 @@ comp_init(const struct compress_options *opt)
 #endif
 #ifdef ENABLE_SNAPPY
     case COMP_ALG_SNAPPY:
-      ALLOC_OBJ_CLEAR (compctx, struct compress_context);
+      ALLOC_OBJ (compctx, struct compress_context);
       compctx->flags = opt->flags;
       compctx->alg = snappy_alg;
       (*compctx->alg.compress_init)(compctx);
src/openvpn/event.c +4 -4
index 34a3c45..e8ebbd2 100644
@@ -432,7 +432,7 @@ we_init (int *maxevents, unsigned int flags)
 
   dmsg (D_EVENT_WAIT, "WE_INIT maxevents=%d flags=0x%08x", *maxevents, flags);
 
-  ALLOC_OBJ_CLEAR (wes, struct we_set);
+  ALLOC_OBJ (wes, struct we_set);
 
   /* set dispatch functions */
   wes->func.free = we_free;
@@ -585,7 +585,7 @@ ep_init (int *maxevents, unsigned int flags)
 
   set_cloexec (fd);
 
-  ALLOC_OBJ_CLEAR (eps, struct ep_set);
+  ALLOC_OBJ (eps, struct ep_set);
 
   /* set dispatch functions */
   eps->func.free = ep_free;
@@ -774,7 +774,7 @@ po_init (int *maxevents, unsigned int flags)
 
   dmsg (D_EVENT_WAIT, "PO_INIT maxevents=%d flags=0x%08x", *maxevents, flags);
 
-  ALLOC_OBJ_CLEAR (pos, struct po_set);
+  ALLOC_OBJ (pos, struct po_set);
 
   /* set dispatch functions */
   pos->func.free = po_free;
@@ -973,7 +973,7 @@ se_init (int *maxevents, unsigned int flags)
 
   dmsg (D_EVENT_WAIT, "SE_INIT maxevents=%d flags=0x%08x", *maxevents, flags);
 
-  ALLOC_OBJ_CLEAR (ses, struct se_set);
+  ALLOC_OBJ (ses, struct se_set);
 
   /* set dispatch functions */
   ses->func.free = se_free;
src/openvpn/fragment.c +1 -1
index 7ad1d61..7da9098 100644
@@ -88,7 +88,7 @@ fragment_init (struct frame *frame)
 
   /* code that initializes other parts of
      fragment_master assume an initial CLEAR */
-  ALLOC_OBJ_CLEAR (ret, struct fragment_master);
+  ALLOC_OBJ (ret, struct fragment_master);
 
   /* add in the size of our contribution to the expanded frame size */
   frame_add_to_extra_frame (frame, sizeof(fragment_header_type));
src/openvpn/init.c +1 -1
index ba15fe3..705d50b 100644
@@ -2568,7 +2568,7 @@ init_context_buffers (const struct frame *frame)
 {
   struct context_buffers *b;
 
-  ALLOC_OBJ_CLEAR (b, struct context_buffers);
+  ALLOC_OBJ (b, struct context_buffers);
 
   b->read_link_buf = alloc_buf (BUF_SIZE (frame));
   b->read_tun_buf = alloc_buf (BUF_SIZE (frame));
src/openvpn/list.c +1 -1
index ea6bd74..df13450 100644
@@ -47,7 +47,7 @@ hash_init (const int n_buckets,
   int i;
 
   ASSERT (n_buckets > 0);
-  ALLOC_OBJ_CLEAR (h, struct hash);
+  ALLOC_OBJ (h, struct hash);
   h->n_buckets = (int) adjust_power_of_2 (n_buckets);
   h->mask = h->n_buckets - 1;
   h->hash_function = hash_function;
src/openvpn/manage.c +2 -2
index 9c40fbe..6c4070f 100644
@@ -2233,7 +2233,7 @@ struct management *
 management_init (void)
 {
   struct management *man;
-  ALLOC_OBJ_CLEAR (man, struct management);
+  ALLOC_OBJ (man, struct management);
 
   man_persist_init (man,
 		    MANAGEMENT_LOG_HISTORY_INITIAL_SIZE,
@@ -3204,7 +3204,7 @@ struct command_line *
 command_line_new (const int buf_len)
 {
   struct command_line *cl;
-  ALLOC_OBJ_CLEAR (cl, struct command_line);
+  ALLOC_OBJ (cl, struct command_line);
   cl->buf = alloc_buf (buf_len);
   cl->residual = alloc_buf (buf_len);
   return cl;
src/openvpn/mbuf.c +1 -1
index 82f2388..0d0fe56 100644
@@ -43,7 +43,7 @@ struct mbuf_set *
 mbuf_init (unsigned int size)
 {
   struct mbuf_set *ret;
-  ALLOC_OBJ_CLEAR (ret, struct mbuf_set);
+  ALLOC_OBJ (ret, struct mbuf_set);
   ret->capacity = adjust_power_of_2 (size);
   ALLOC_ARRAY (ret->array, struct mbuf_item, ret->capacity);
   return ret;
src/openvpn/mroute.c +1 -1
index 850e336..f03a8b7 100644
@@ -454,7 +454,7 @@ struct mroute_helper *
 mroute_helper_init (int ageable_ttl_secs)
 {
   struct mroute_helper *mh;
-  ALLOC_OBJ_CLEAR (mh, struct mroute_helper);
+  ALLOC_OBJ (mh, struct mroute_helper);
   mh->ageable_ttl_secs = ageable_ttl_secs;
   return mh;
 }
src/openvpn/mtcp.c +1 -1
index dc15f09..5db7dcf 100644
@@ -182,7 +182,7 @@ multi_tcp_init (int maxevents, int *maxclients)
   ASSERT (maxevents >= 1);
   ASSERT (maxclients);
 
-  ALLOC_OBJ_CLEAR (mtcp, struct multi_tcp);
+  ALLOC_OBJ (mtcp, struct multi_tcp);
   mtcp->maxevents = maxevents + extra_events;
   mtcp->es = event_set_init (&mtcp->maxevents, 0);
   wait_signal (mtcp->es, MTCP_SIG);
src/openvpn/multi.c +1 -1
index f016b14..2cb37c8 100644
@@ -653,7 +653,7 @@ multi_create_instance (struct multi_context *m, const struct mroute_addr *real)
 
   msg (D_MULTI_MEDIUM, "MULTI: multi_create_instance called");
 
-  ALLOC_OBJ_CLEAR (mi, struct multi_instance);
+  ALLOC_OBJ (mi, struct multi_instance);
 
   mi->gc = gc_new ();
   multi_instance_inc_refcount (mi);
src/openvpn/pf.c +4 -4
index 461beed..8f4ca72 100644
@@ -75,7 +75,7 @@ static bool
 add_client (const char *line, const char *prefix, const int line_num, struct pf_cn_elem ***next, const bool exclude)
 {
   struct pf_cn_elem *e;
-  ALLOC_OBJ_CLEAR (e, struct pf_cn_elem);
+  ALLOC_OBJ (e, struct pf_cn_elem);
   e->rule.exclude = exclude;
   e->rule.cn = string_alloc (line, NULL);
   **next = e;
@@ -130,7 +130,7 @@ add_subnet (const char *line, const char *prefix, const int line_num, struct pf_
 
   {
     struct pf_subnet *e;
-    ALLOC_OBJ_CLEAR (e, struct pf_subnet);
+    ALLOC_OBJ (e, struct pf_subnet);
     e->rule.exclude = exclude;
     e->rule.network = ntohl (network.s_addr);
     e->rule.netmask = netmask;
@@ -188,7 +188,7 @@ pf_init (const struct buffer_list *bl, const char *prefix, const bool allow_kill
   struct pf_set *pfs = NULL;
   char line[PF_MAX_LINE_LEN];
 
-  ALLOC_OBJ_CLEAR (pfs, struct pf_set);
+  ALLOC_OBJ (pfs, struct pf_set);
   if (bl)
     {
       struct pf_cn_elem **cl = &pfs->cns.list;
@@ -300,7 +300,7 @@ pf_init (const struct buffer_list *bl, const char *prefix, const bool allow_kill
   
  kill:
   pf_destroy (pfs);
-  ALLOC_OBJ_CLEAR (pfs, struct pf_set);
+  ALLOC_OBJ (pfs, struct pf_set);
   pfs->kill = true;
   return pfs;
 }
src/openvpn/plugin.c +3 -3
index 71ad0b6..cad98ac 100644
@@ -561,7 +561,7 @@ struct plugin_list *
 plugin_list_inherit (const struct plugin_list *src)
 {
   struct plugin_list *pl;
-  ALLOC_OBJ_CLEAR (pl, struct plugin_list);
+  ALLOC_OBJ (pl, struct plugin_list);
   pl->common = src->common;
   ASSERT (pl->common);
   plugin_per_client_init (pl->common, &pl->per_client, -1);
@@ -574,7 +574,7 @@ plugin_common_init (const struct plugin_option_list *list)
   int i;
   struct plugin_common *pc;
 
-  ALLOC_OBJ_CLEAR (pc, struct plugin_common);
+  ALLOC_OBJ (pc, struct plugin_common);
 
   for (i = 0; i < list->n; ++i)
     {
@@ -636,7 +636,7 @@ struct plugin_list *
 plugin_list_init (const struct plugin_option_list *list)
 {
   struct plugin_list *pl;
-  ALLOC_OBJ_CLEAR (pl, struct plugin_list);
+  ALLOC_OBJ (pl, struct plugin_list);
   pl->common = plugin_common_init (list);
   pl->common_owned = true;
   return pl;
src/openvpn/pool.c +2 -2
index 28c26b4..0addda7 100644
@@ -147,7 +147,7 @@ ifconfig_pool_init (int type, in_addr_t start, in_addr_t end,
   struct ifconfig_pool *pool = NULL;
 
   ASSERT (start <= end && end - start < IFCONFIG_POOL_MAX);
-  ALLOC_OBJ_CLEAR (pool, struct ifconfig_pool);
+  ALLOC_OBJ (pool, struct ifconfig_pool);
 
   pool->type = type;
   pool->duplicate_cn = duplicate_cn;
@@ -406,7 +406,7 @@ ifconfig_pool_persist_init (const char *filename, int refresh_freq)
 
   ASSERT (filename);
 
-  ALLOC_OBJ_CLEAR (ret, struct ifconfig_pool_persist);
+  ALLOC_OBJ (ret, struct ifconfig_pool_persist);
   if (refresh_freq > 0)
     {
       ret->fixed = false;
src/openvpn/proxy.c +1 -1
index 9ef1b8f..58e1338 100644
@@ -445,7 +445,7 @@ http_proxy_new (const struct http_proxy_options *o)
 
   ASSERT (legal_ipv4_port (o->port));
 
-  ALLOC_OBJ_CLEAR (p, struct http_proxy_info);
+  ALLOC_OBJ (p, struct http_proxy_info);
   p->options = *o;
 
   /* parse authentication method */
src/openvpn/ps.c +3 -3
index f6b5212..d68e47d 100644
@@ -435,8 +435,8 @@ proxy_entry_new (struct proxy_connection **list,
   set_nonblock (sd_server);
 
   /* allocate 2 new proxy_connection objects */
-  ALLOC_OBJ_CLEAR (pc, struct proxy_connection);
-  ALLOC_OBJ_CLEAR (cp, struct proxy_connection);
+  ALLOC_OBJ (pc, struct proxy_connection);
+  ALLOC_OBJ (cp, struct proxy_connection);
 
   /* client object */
   pc->defined = true;
@@ -798,7 +798,7 @@ port_share_open (const char *host,
   in_addr_t hostaddr;
   struct port_share *ps;
 
-  ALLOC_OBJ_CLEAR (ps, struct port_share);
+  ALLOC_OBJ (ps, struct port_share);
   ps->foreground_fd = -1;
   ps->background_pid = -1;
 
src/openvpn/schedule.c +2 -2
index 471330f..520992b 100644
@@ -368,7 +368,7 @@ schedule_init (void)
 {
   struct schedule *s;
 
-  ALLOC_OBJ_CLEAR (s, struct schedule);
+  ALLOC_OBJ (s, struct schedule);
   return s;
 }
 
@@ -605,7 +605,7 @@ schedule_test (void)
 
   for (i = 0; i < n; ++i)
     {
-      ALLOC_OBJ_CLEAR (array[i], struct schedule_entry);
+      ALLOC_OBJ (array[i], struct schedule_entry);
       tv_randomize (&array[i]->tv);
       /*schedule_print (s);*/
       /*schedule_verify (s);*/
src/openvpn/socket.c +1 -1
index 3c0a379..7e44569 100644
@@ -1335,7 +1335,7 @@ link_socket_new (void)
 {
   struct link_socket *sock;
 
-  ALLOC_OBJ_CLEAR (sock, struct link_socket);
+  ALLOC_OBJ (sock, struct link_socket);
   sock->sd = SOCKET_UNDEFINED;
 #ifdef ENABLE_SOCKS
   sock->ctrl_sd = SOCKET_UNDEFINED;
src/openvpn/socks.c +1 -1
index 235982e..874c95e 100644
@@ -67,7 +67,7 @@ socks_proxy_new (const char *server,
 {
   struct socks_proxy_info *p;
 
-  ALLOC_OBJ_CLEAR (p, struct socks_proxy_info);
+  ALLOC_OBJ (p, struct socks_proxy_info);
 
   ASSERT (server);
   ASSERT (legal_ipv4_port (port));
src/openvpn/ssl.c +5 -5
index 7ceb79b..1650b27 100644
@@ -733,12 +733,12 @@ key_state_init (struct tls_session *session, struct key_state *ks)
     session->key_id = 1;
 
   /* allocate key source material object */
-  ALLOC_OBJ_CLEAR (ks->key_src, struct key_source2);
+  ALLOC_OBJ (ks->key_src, struct key_source2);
 
   /* allocate reliability objects */
-  ALLOC_OBJ_CLEAR (ks->send_reliable, struct reliable);
-  ALLOC_OBJ_CLEAR (ks->rec_reliable, struct reliable);
-  ALLOC_OBJ_CLEAR (ks->rec_ack, struct reliable_ack);
+  ALLOC_OBJ (ks->send_reliable, struct reliable);
+  ALLOC_OBJ (ks->rec_reliable, struct reliable);
+  ALLOC_OBJ (ks->rec_ack, struct reliable_ack);
 
   /* allocate buffers */
   ks->plaintext_read_buf = alloc_buf (TLS_CHANNEL_BUF_SIZE);
@@ -1030,7 +1030,7 @@ tls_multi_init (struct tls_options *tls_options)
 {
   struct tls_multi *ret;
 
-  ALLOC_OBJ_CLEAR (ret, struct tls_multi);
+  ALLOC_OBJ (ret, struct tls_multi);
 
   /* get command line derived options */
   ret->opt = *tls_options;
src/openvpn/ssl_openssl.c +1 -1
index e392691..5399f5f 100644
@@ -675,7 +675,7 @@ tls_ctx_use_external_private_key (struct tls_root_ctx *ctx, X509 *cert)
   ASSERT (NULL != cert);
 
   /* allocate custom RSA method object */
-  ALLOC_OBJ_CLEAR (rsa_meth, RSA_METHOD);
+  ALLOC_OBJ (rsa_meth, RSA_METHOD);
   rsa_meth->name = "OpenVPN external private key RSA Method";
   rsa_meth->rsa_pub_enc = rsa_pub_enc;
   rsa_meth->rsa_pub_dec = rsa_pub_dec;
src/openvpn/ssl_polarssl.c +11 -11
index fb73225..83d5ae2 100644
@@ -71,11 +71,11 @@ tls_ctx_server_new(struct tls_root_ctx *ctx)
   ASSERT(NULL != ctx);
   CLEAR(*ctx);
 
-  ALLOC_OBJ_CLEAR(ctx->dhm_ctx, dhm_context);
-  ALLOC_OBJ_CLEAR(ctx->priv_key, rsa_context);
+  ALLOC_OBJ (ctx->dhm_ctx, dhm_context);
+  ALLOC_OBJ (ctx->priv_key, rsa_context);
 
-  ALLOC_OBJ_CLEAR(ctx->ca_chain, x509_cert);
-  ALLOC_OBJ_CLEAR(ctx->crt_chain, x509_cert);
+  ALLOC_OBJ (ctx->ca_chain, x509_cert);
+  ALLOC_OBJ (ctx->crt_chain, x509_cert);
 
 
   ctx->endpoint = SSL_IS_SERVER;
@@ -88,11 +88,11 @@ tls_ctx_client_new(struct tls_root_ctx *ctx)
   ASSERT(NULL != ctx);
   CLEAR(*ctx);
 
-  ALLOC_OBJ_CLEAR(ctx->dhm_ctx, dhm_context);
-  ALLOC_OBJ_CLEAR(ctx->priv_key, rsa_context);
+  ALLOC_OBJ (ctx->dhm_ctx, dhm_context);
+  ALLOC_OBJ (ctx->priv_key, rsa_context);
 
-  ALLOC_OBJ_CLEAR(ctx->ca_chain, x509_cert);
-  ALLOC_OBJ_CLEAR(ctx->crt_chain, x509_cert);
+  ALLOC_OBJ (ctx->ca_chain, x509_cert);
+  ALLOC_OBJ (ctx->crt_chain, x509_cert);
 
   ctx->endpoint = SSL_IS_CLIENT;
   ctx->initialised = true;
@@ -520,7 +520,7 @@ void key_state_ssl_init(struct key_state_ssl *ks_ssl,
   ASSERT(ks_ssl);
   CLEAR(*ks_ssl);
 
-  ALLOC_OBJ_CLEAR(ks_ssl->ctx, ssl_context);
+  ALLOC_OBJ (ks_ssl->ctx, ssl_context);
   if (0 == ssl_init(ks_ssl->ctx))
     {
       /* Initialise SSL context */
@@ -591,8 +591,8 @@ void key_state_ssl_init(struct key_state_ssl *ks_ssl,
       }
 
       /* Initialise BIOs */
-      ALLOC_OBJ_CLEAR (ks_ssl->ct_in, endless_buffer);
-      ALLOC_OBJ_CLEAR (ks_ssl->ct_out, endless_buffer);
+      ALLOC_OBJ (ks_ssl->ct_in, endless_buffer);
+      ALLOC_OBJ (ks_ssl->ct_out, endless_buffer);
       ssl_set_bio (ks_ssl->ctx, endless_buf_read, ks_ssl->ct_in,
 	  endless_buf_write, ks_ssl->ct_out);
     }
src/openvpn/ssl_verify.c +2 -2
index 4dd3aa2..43579c7 100644
@@ -196,7 +196,7 @@ cert_hash_remember (struct tls_session *session, const int error_depth, const un
   if (error_depth >= 0 && error_depth < MAX_CERT_DEPTH)
     {
       if (!session->cert_hash_set)
-	ALLOC_OBJ_CLEAR (session->cert_hash_set, struct cert_hash_set);
+	ALLOC_OBJ (session->cert_hash_set, struct cert_hash_set);
       if (!session->cert_hash_set->ch[error_depth])
 	ALLOC_OBJ (session->cert_hash_set->ch[error_depth], struct cert_hash);
       {
@@ -271,7 +271,7 @@ cert_hash_copy (const struct cert_hash_set *chs)
   if (chs)
     {
       int i;
-      ALLOC_OBJ_CLEAR (dest, struct cert_hash_set);
+      ALLOC_OBJ (dest, struct cert_hash_set);
       for (i = 0; i < MAX_CERT_DEPTH; ++i)
 	{
 	  const struct cert_hash *ch = chs->ch[i];
src/openvpn/status.c +1 -1
index b7ff484..1f492d5 100644
@@ -67,7 +67,7 @@ status_open (const char *filename,
   struct status_output *so = NULL;
   if (filename || msglevel >= 0 || vout)
     {
-      ALLOC_OBJ_CLEAR (so, struct status_output);
+      ALLOC_OBJ (so, struct status_output);
       so->flags = flags;
       so->msglevel = msglevel;
       so->vout = vout;
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/4 Merge the rest of ALLOC_*_CLEAR*() macros into ALLOC_*()

In reply to David Sommerseth

From: David Sommerseth <[email protected]...>

This is the last patch in the malloc() -> calloc() move.

This patch only reduces the ALLOC_*() macro API further by removing duplicated macros, where the version with _CLEAR would now do the same thing as the one without _CLEAR.

---
 src/openvpn/buffer.h             | 18 +-----------------
 src/openvpn/clinat.c             |  2 +-
 src/openvpn/event.c              | 12 ++++++------
 src/openvpn/init.c               |  6 +++---
 src/openvpn/manage.c             |  2 +-
 src/openvpn/misc.c               | 14 +++++++-------
 src/openvpn/options.c            |  8 ++++----
 src/openvpn/plugin.c             |  2 +-
 src/openvpn/pool.c               |  6 +++---
 src/openvpn/proxy.c              |  2 +-
 src/openvpn/push.c               |  2 +-
 src/openvpn/route.c              |  8 ++++----
 src/openvpn/ssl.c                |  6 +++---
 src/openvpn/ssl_polarssl.c       |  2 +-
 src/openvpn/ssl_verify.c         |  2 +-
 src/openvpn/ssl_verify_openssl.c |  2 +-
 src/openvpn/tun.c                |  4 ++--
 17 files changed, 41 insertions(+), 57 deletions(-)
src/openvpn/buffer.h +1 -17
index 81d8fea..ca599d7 100644
@@ -837,18 +837,7 @@ gc_reset (struct gc_arena *a)
   (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (type), (n), 0), (gc)); \
 }
 
-#define ALLOC_ARRAY_CLEAR(dptr, type, n) \
-{ \
-  ALLOC_ARRAY (dptr, type, n); \
-  memset ((dptr), 0, (array_mult_safe (sizeof(type), (n), 0)));	\
-}
-
-#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc) \
-{ \
-  (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (type), (n), 0), (gc)); \
-}
-
-#define ALLOC_VAR_ARRAY_CLEAR_GC(dptr, type, atype, n, gc)	\
+#define ALLOC_VAR_ARRAY_GC(dptr, type, atype, n, gc)     \
 { \
   (dptr) = (type *) gc_malloc (array_mult_safe (sizeof (atype), (n), sizeof (type)), (gc)); \
 }
@@ -858,11 +847,6 @@ gc_reset (struct gc_arena *a)
   (dptr) = (type *) gc_malloc (sizeof (type), (gc)); \
 }
 
-#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc) \
-{ \
-  (dptr) = (type *) gc_malloc (sizeof (type), (gc)); \
-}
-
 static inline void
 check_malloc_return (void *p)
 {
src/openvpn/clinat.c +1 -1
index af75fc9..442506d 100644
@@ -80,7 +80,7 @@ struct client_nat_option_list *
 new_client_nat_list (struct gc_arena *gc)
 {
   struct client_nat_option_list *ret;
-  ALLOC_OBJ_CLEAR_GC (ret, struct client_nat_option_list, gc);
+  ALLOC_OBJ_GC (ret, struct client_nat_option_list, gc);
   return ret;
 }
 
src/openvpn/event.c +6 -6
index e8ebbd2..933b68b 100644
@@ -451,10 +451,10 @@ we_init (int *maxevents, unsigned int flags)
   *maxevents = min_int (*maxevents, WSA_MAXIMUM_WAIT_EVENTS);
 
   /* Allocate space for Win32 event handles */
-  ALLOC_ARRAY_CLEAR (wes->events, HANDLE, wes->capacity);
+  ALLOC_ARRAY (wes->events, HANDLE, wes->capacity);
 
   /* Allocate space for event_set_return objects */
-  ALLOC_ARRAY_CLEAR (wes->esr, struct event_set_return, wes->capacity);
+  ALLOC_ARRAY (wes->esr, struct event_set_return, wes->capacity);
 
   dmsg (D_EVENT_WAIT, "WE_INIT maxevents=%d capacity=%d",
        *maxevents, wes->capacity);
@@ -601,7 +601,7 @@ ep_init (int *maxevents, unsigned int flags)
   /* allocate space for epoll_wait return */
   ASSERT (*maxevents > 0);
   eps->maxevents = *maxevents;
-  ALLOC_ARRAY_CLEAR (eps->events, struct epoll_event, eps->maxevents);
+  ALLOC_ARRAY (eps->events, struct epoll_event, eps->maxevents);
 
   /* set epoll control fd */
   eps->epfd = fd;
@@ -793,10 +793,10 @@ po_init (int *maxevents, unsigned int flags)
   pos->capacity = *maxevents;
 
   /* Allocate space for pollfd structures to be passed to poll() */
-  ALLOC_ARRAY_CLEAR (pos->events, struct pollfd, pos->capacity);
+  ALLOC_ARRAY (pos->events, struct pollfd, pos->capacity);
 
   /* Allocate space for event_set_return objects */
-  ALLOC_ARRAY_CLEAR (pos->args, void *, pos->capacity);
+  ALLOC_ARRAY (pos->args, void *, pos->capacity);
 
   return (struct event_set *) pos;
 }
@@ -997,7 +997,7 @@ se_init (int *maxevents, unsigned int flags)
   ses->capacity = SELECT_MAX_FDS;
 
   /* Allocate space for event_set_return void * args */
-  ALLOC_ARRAY_CLEAR (ses->args, void *, ses->capacity);
+  ALLOC_ARRAY (ses->args, void *, ses->capacity);
 
   return (struct event_set *) ses;
 }
src/openvpn/init.c +3 -3
index 705d50b..92519f0 100644
@@ -233,7 +233,7 @@ management_callback_remote_cmd (void *arg, const char **p)
 	      struct remote_host_store *rhs = c->options.rh_store;
 	      if (!rhs)
 		{
-		  ALLOC_OBJ_CLEAR_GC (rhs, struct remote_host_store, &c->options.gc);
+		  ALLOC_OBJ_GC (rhs, struct remote_host_store, &c->options.gc);
 		  c->options.rh_store = rhs;
 		}
 	      strncpynt(rhs->host, p[2], RH_HOST_LEN);
@@ -2785,7 +2785,7 @@ do_init_first_time (struct context *c)
     {
       struct context_0 *c0;
 
-      ALLOC_OBJ_CLEAR_GC (c->c0, struct context_0, &c->gc);
+      ALLOC_OBJ_GC (c->c0, struct context_0, &c->gc);
       c0 = c->c0;
       
       /* get user and/or group that we want to setuid/setgid to */
@@ -3621,7 +3621,7 @@ inherit_context_child (struct context *dest,
 
   dest->gc = gc_new ();
 
-  ALLOC_OBJ_CLEAR_GC (dest->sig, struct signal_info, &dest->gc);
+  ALLOC_OBJ_GC (dest->sig, struct signal_info, &dest->gc);
 
   /* c1 init */
   packet_id_persist_init (&dest->c1.pid_persist);
src/openvpn/manage.c +1 -1
index 6c4070f..f1e3411 100644
@@ -3324,7 +3324,7 @@ log_history_obj_init (struct log_history *h, int capacity)
 {
   CLEAR (*h);
   h->capacity = capacity;
-  ALLOC_ARRAY_CLEAR (h->array, struct log_entry, capacity);
+  ALLOC_ARRAY (h->array, struct log_entry, capacity);
 }
 
 struct log_history *
src/openvpn/misc.c +7 -7
index 2132649..440727e 100644
@@ -570,7 +570,7 @@ struct env_set *
 env_set_create (struct gc_arena *gc)
 {
   struct env_set *es;
-  ALLOC_OBJ_CLEAR_GC (es, struct env_set, gc);
+  ALLOC_OBJ_GC (es, struct env_set, gc);
   es->list = NULL;
   es->gc = gc;
   return es;
@@ -1234,7 +1234,7 @@ get_auth_challenge (const char *auth_challenge, struct gc_arena *gc)
       struct buffer b;
       buf_set_read (&b, (const uint8_t *)auth_challenge, len);
 
-      ALLOC_OBJ_CLEAR_GC (ac, struct auth_challenge_info, gc);
+      ALLOC_OBJ_GC (ac, struct auth_challenge_info, gc);
 
       /* parse prefix */
       if (!buf_parse(&b, ':', work, len))
@@ -1397,7 +1397,7 @@ make_env_array (const struct env_set *es,
     }
 
   /* alloc return array */
-  ALLOC_ARRAY_CLEAR_GC (ret, char *, n+1, gc);
+  ALLOC_ARRAY_GC (ret, char *, n+1, gc);
 
   /* fill return array */
   if (es)
@@ -1426,7 +1426,7 @@ make_arg_array (const char *first, const char *parms, struct gc_arena *gc)
   int n = 0;
 
   /* alloc return array */
-  ALLOC_ARRAY_CLEAR_GC (ret, char *, max_parms, gc);
+  ALLOC_ARRAY_GC (ret, char *, max_parms, gc);
 
   /* process first parameter, if provided */
   if (first)
@@ -1458,7 +1458,7 @@ make_inline_array (const char *str, struct gc_arena *gc)
     ++len;
 
   /* alloc return array */
-  ALLOC_ARRAY_CLEAR_GC (ret, char *, len + 1, gc);
+  ALLOC_ARRAY_GC (ret, char *, len + 1, gc);
 
   buf_set_read (&buf, (const uint8_t *) str, strlen(str));
   while (buf_parse (&buf, '\n', line, sizeof (line)))
@@ -1482,7 +1482,7 @@ make_arg_copy (char **p, struct gc_arena *gc)
   int i;
 
   /* alloc return array */
-  ALLOC_ARRAY_CLEAR_GC (ret, char *, max_parms, gc);
+  ALLOC_ARRAY_GC (ret, char *, max_parms, gc);
 
   for (i = 0; i < len; ++i)
     ret[i] = p[i];
@@ -1580,7 +1580,7 @@ argv_extend (struct argv *a, const size_t newcap)
     {
       char **newargv;
       size_t i;
-      ALLOC_ARRAY_CLEAR (newargv, char *, newcap);
+      ALLOC_ARRAY(newargv, char *, newcap);
       for (i = 0; i < a->argc; ++i)
 	newargv[i] = a->argv[i];
       free (a->argv);
src/openvpn/options.c +4 -4
index 81e9a6e..76a33e6 100644
@@ -1713,7 +1713,7 @@ parse_http_proxy_override (const char *server,
 	  return NULL;
 	}
 
-      ALLOC_OBJ_CLEAR_GC (ho, struct http_proxy_options, gc);
+      ALLOC_OBJ_GC (ho, struct http_proxy_options, gc);
       ho->server = string_alloc(server, gc);
       ho->port = int_port;
       ho->retry = true;
@@ -1769,7 +1769,7 @@ static struct connection_list *
 alloc_connection_list_if_undef (struct options *options)
 {
   if (!options->connection_list)
-    ALLOC_OBJ_CLEAR_GC (options->connection_list, struct connection_list, &options->gc);
+    ALLOC_OBJ_GC (options->connection_list, struct connection_list, &options->gc);
   return options->connection_list;
 }
 
@@ -1793,7 +1793,7 @@ static struct remote_list *
 alloc_remote_list_if_undef (struct options *options)
 {
   if (!options->remote_list)
-    ALLOC_OBJ_CLEAR_GC (options->remote_list, struct remote_list, &options->gc);
+    ALLOC_OBJ_GC (options->remote_list, struct remote_list, &options->gc);
   return options->remote_list;
 }
 
@@ -2788,7 +2788,7 @@ pre_pull_save (struct options *o)
 {
   if (o->pull)
     {
-      ALLOC_OBJ_CLEAR_GC (o->pre_pull, struct options_pre_pull, &o->gc);
+      ALLOC_OBJ_GC (o->pre_pull, struct options_pre_pull, &o->gc);
       o->pre_pull->tuntap_options = o->tuntap_options;
       o->pre_pull->tuntap_options_defined = true;
       o->pre_pull->foreign_option_index = o->foreign_option_index;
src/openvpn/plugin.c +1 -1
index cad98ac..d8b2acc 100644
@@ -136,7 +136,7 @@ struct plugin_option_list *
 plugin_option_list_new (struct gc_arena *gc)
 {
   struct plugin_option_list *ret;
-  ALLOC_OBJ_CLEAR_GC (ret, struct plugin_option_list, gc);
+  ALLOC_OBJ_GC (ret, struct plugin_option_list, gc);
   return ret;
 }
 
src/openvpn/pool.c +3 -3
index 0addda7..dfba34c 100644
@@ -186,7 +186,7 @@ ifconfig_pool_init (int type, in_addr_t start, in_addr_t end,
       ASSERT( pool->size < pool->size_ipv6 );
     }
 
-  ALLOC_ARRAY_CLEAR (pool->list, struct ifconfig_pool_entry, pool->size);
+  ALLOC_ARRAY (pool->list, struct ifconfig_pool_entry, pool->size);
 
   msg (D_IFCONFIG_POOL, "IFCONFIG POOL: base=%s size=%d, ipv6=%d",
        print_in_addr_t (pool->base, 0, &gc),
@@ -454,8 +454,8 @@ ifconfig_pool_read (struct ifconfig_pool_persist *persist, struct ifconfig_pool
       char *ip_buf;
       int line = 0;
 
-      ALLOC_ARRAY_CLEAR_GC (cn_buf, char, buf_size, &gc);
-      ALLOC_ARRAY_CLEAR_GC (ip_buf, char, buf_size, &gc);
+      ALLOC_ARRAY_GC (cn_buf, char, buf_size, &gc);
+      ALLOC_ARRAY_GC (ip_buf, char, buf_size, &gc);
 
       while (true)
 	{
src/openvpn/proxy.c +1 -1
index 58e1338..54b04af 100644
@@ -52,7 +52,7 @@ init_http_proxy_options_once (struct http_proxy_options **hpo,
 {
   if (!*hpo)
     {
-      ALLOC_OBJ_CLEAR_GC (*hpo, struct http_proxy_options, gc);
+      ALLOC_OBJ_GC (*hpo, struct http_proxy_options, gc);
       /* http proxy defaults */
       (*hpo)->timeout = 5;
       (*hpo)->http_version = "1.0";
src/openvpn/push.c +1 -1
index be50bef..882ff90 100644
@@ -341,7 +341,7 @@ push_option_ex (struct options *o, const char *opt, bool enable, int msglevel)
   else
     {
       struct push_entry *e;
-      ALLOC_OBJ_CLEAR_GC (e, struct push_entry, &o->gc);
+      ALLOC_OBJ_GC (e, struct push_entry, &o->gc);
       e->enable = true;
       e->option = opt;
       if (o->push_list.head)
src/openvpn/route.c +4 -4
index 37ef096..aeee883 100644
@@ -95,7 +95,7 @@ struct route_option_list *
 new_route_option_list (const int max_routes, struct gc_arena *a)
 {
   struct route_option_list *ret;
-  ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_option_list, struct route_option, max_routes, a);
+  ALLOC_VAR_ARRAY_GC (ret, struct route_option_list, struct route_option, max_routes, a);
   ret->capacity = max_routes;
   return ret;
 }
@@ -104,7 +104,7 @@ struct route_ipv6_option_list *
 new_route_ipv6_option_list (const int max_routes, struct gc_arena *a)
 {
   struct route_ipv6_option_list *ret;
-  ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_ipv6_option_list, struct route_ipv6_option, max_routes, a);
+  ALLOC_VAR_ARRAY_GC (ret, struct route_ipv6_option_list, struct route_ipv6_option, max_routes, a);
   ret->capacity = max_routes;
   return ret;
 }
@@ -150,7 +150,7 @@ struct route_list *
 new_route_list (const int max_routes, struct gc_arena *a)
 {
   struct route_list *ret;
-  ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_list, struct route, max_routes, a);
+  ALLOC_VAR_ARRAY_GC (ret, struct route_list, struct route, max_routes, a);
   ret->capacity = max_routes;
   return ret;
 }
@@ -159,7 +159,7 @@ struct route_ipv6_list *
 new_route_ipv6_list (const int max_routes, struct gc_arena *a)
 {
   struct route_ipv6_list *ret;
-  ALLOC_VAR_ARRAY_CLEAR_GC (ret, struct route_ipv6_list, struct route_ipv6, max_routes, a);
+  ALLOC_VAR_ARRAY_GC (ret, struct route_ipv6_list, struct route_ipv6, max_routes, a);
   ret->capacity = max_routes;
   return ret;
 }
src/openvpn/ssl.c +3 -3
index 1650b27..c30969d 100644
@@ -1070,7 +1070,7 @@ tls_auth_standalone_init (struct tls_options *tls_options,
 {
   struct tls_auth_standalone *tas;
 
-  ALLOC_OBJ_CLEAR_GC (tas, struct tls_auth_standalone, gc);
+  ALLOC_OBJ_GC (tas, struct tls_auth_standalone, gc);
 
   /* set up pointer to HMAC object for TLS packet authentication */
   tas->tls_auth_key = tls_options->tls_auth_key;
@@ -2014,7 +2014,7 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi
   struct user_pass *up;
 
   /* allocate temporary objects */
-  ALLOC_ARRAY_CLEAR_GC (options, char, TLS_OPTIONS_LEN, &gc);
+  ALLOC_ARRAY_GC (options, char, TLS_OPTIONS_LEN, &gc);
 
   ASSERT (session->opt->key_method == 2);
 
@@ -2051,7 +2051,7 @@ key_method_2_read (struct buffer *buf, struct tls_multi *multi, struct tls_sessi
    * authenticating for it, because otherwise we can't get at the
    * peer_info data which follows behind
    */
-  ALLOC_OBJ_CLEAR_GC (up, struct user_pass, &gc);
+  ALLOC_OBJ_GC (up, struct user_pass, &gc);
   username_status = read_string (buf, up->username, USER_PASS_LEN);
   password_status = read_string (buf, up->password, USER_PASS_LEN);
 
src/openvpn/ssl_polarssl.c +1 -1
index 83d5ae2..0e086ec 100644
@@ -179,7 +179,7 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
       cipher_count++;
 
   /* Allocate an array for them */
-  ALLOC_ARRAY_CLEAR(ctx->allowed_ciphers, int, cipher_count+1)
+  ALLOC_ARRAY (ctx->allowed_ciphers, int, cipher_count+1)
 
   /* Parse allowed ciphers, getting IDs */
   i = 0;
src/openvpn/ssl_verify.c +1 -1
index 43579c7..28768ef 100644
@@ -1142,7 +1142,7 @@ verify_user_pass(struct user_pass *up, struct tls_multi *multi,
    */
   if (compat_flag (COMPAT_FLAG_QUERY | COMPAT_NAMES))
     {
-      ALLOC_ARRAY_CLEAR_GC (raw_username, char, USER_PASS_LEN, &gc);
+      ALLOC_ARRAY_GC (raw_username, char, USER_PASS_LEN, &gc);
       strcpy (raw_username, up->username);
       string_mod (raw_username, CC_PRINT, CC_CRLF, '_');
     }
src/openvpn/ssl_verify_openssl.c +1 -1
index 176669f..28ac18a 100644
@@ -299,7 +299,7 @@ void
 x509_track_add (const struct x509_track **ll_head, const char *name, int msglevel, struct gc_arena *gc)
 {
   struct x509_track *xt;
-  ALLOC_OBJ_CLEAR_GC (xt, struct x509_track, gc);
+  ALLOC_OBJ_GC (xt, struct x509_track, gc);
   if (*name == '+')
     {
       xt->flags |= XT_FULL_CHAIN;
src/openvpn/tun.c +2 -2
index de7ccb9..ca35a01 100644
@@ -3095,7 +3095,7 @@ get_tap_reg (struct gc_arena *gc)
 		  if (!strcmp (component_id, TAP_WIN_COMPONENT_ID))
 		    {
 		      struct tap_reg *reg;
-		      ALLOC_OBJ_CLEAR_GC (reg, struct tap_reg, gc);
+		      ALLOC_OBJ_GC (reg, struct tap_reg, gc);
 		      reg->guid = string_alloc (net_cfg_instance_id, gc);
 		      
 		      /* link into return list */
@@ -3194,7 +3194,7 @@ get_panel_reg (struct gc_arena *gc)
               LPSTR name;
 	      struct panel_reg *reg;
 
-	      ALLOC_OBJ_CLEAR_GC (reg, struct panel_reg, gc);
+	      ALLOC_OBJ_GC (reg, struct panel_reg, gc);
               n = WideCharToMultiByte (CP_UTF8, 0, name_data, -1, NULL, 0, NULL, NULL);
               name = gc_malloc (n, gc);
               WideCharToMultiByte (CP_UTF8, 0, name_data, -1, name, n, NULL, NULL);
Signature · 1 line
1.8.3.1