Beispiel #1
0
string_alloc (const char *str, struct gc_arena *gc)
#endif
{
  if (str)
    {
      const int n = strlen (str) + 1;
      char *ret;

      if (gc) {
#ifdef DMALLOC
        ret = (char *) gc_malloc_debug (n, false, gc, file, line);
#else
        ret = (char *) gc_malloc (n, false, gc);
#endif
      } else {
        /* If there are no garbage collector available, it's expected
         * that the caller cleans up afterwards.  This is coherent with the
         * earlier behaviour when gc_malloc() would be called with gc == NULL
         */
#ifdef DMALLOC
        ret = openvpn_dmalloc (file, line, n);
        memset(ret, 0, n);
#else
        ret = calloc(1, n);
#endif
        check_malloc_return(ret);
      }
      memcpy (ret, str, n);
      return ret;
    }
  else
    return NULL;
}
Beispiel #2
0
alloc_buf_gc (size_t size, struct gc_arena *gc)
#endif
{
  struct buffer buf;
  buf.capacity = (int)size;
  buf.offset = 0;
  buf.len = 0;
#ifdef DMALLOC
  buf.data = (uint8_t *) gc_malloc_debug (size, false, gc, file, line);
#else
  buf.data = (uint8_t *) gc_malloc (size, false, gc);
#endif
  if (size)
    *buf.data = 0;
  return buf;
}
Beispiel #3
0
string_alloc (const char *str, struct gc_arena *gc)
#endif
{
  if (str)
    {
      const int n = strlen (str) + 1;
      char *ret;

#ifdef DMALLOC
      ret = (char *) gc_malloc_debug (n, false, gc, file, line);
#else
      ret = (char *) gc_malloc (n, false, gc);
#endif
      memcpy (ret, str, n);
      return ret;
    }
  else
    return NULL;
}