• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ check_malloc_return函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中check_malloc_return函数的典型用法代码示例。如果您正苦于以下问题:C++ check_malloc_return函数的具体用法?C++ check_malloc_return怎么用?C++ check_malloc_return使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了check_malloc_return函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: gc_malloc

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
    {
#ifdef DMALLOC
      ret = openvpn_dmalloc (file, line, size);
#else
      ret = malloc (size);
#endif
      check_malloc_return (ret);
    }
#ifndef ZERO_BUFFER_ON_ALLOC
  if (clear)
#endif
    memset (ret, 0, size);
  return ret;
}
开发者ID:51isoft,项目名称:openvpn-ipv6,代码行数:32,代码来源:buffer.c


示例2: env_block

static char *
env_block(const struct env_set *es)
{
    char force_path[256];
    char *sysroot = get_win_sys_path();

    if (!openvpn_snprintf(force_path, sizeof(force_path), "PATH=%s\\System32;%s;%s\\System32\\Wbem",
                          sysroot, sysroot, sysroot))
    {
        msg(M_WARN, "env_block: default path truncated to %s", force_path);
    }

    if (es)
    {
        struct env_item *e;
        char *ret;
        char *p;
        size_t nchars = 1;
        bool path_seen = false;

        for (e = es->list; e != NULL; e = e->next)
        {
            nchars += strlen(e->string) + 1;
        }

        nchars += strlen(force_path)+1;

        ret = (char *) malloc(nchars);
        check_malloc_return(ret);

        p = ret;
        for (e = es->list; e != NULL; e = e->next)
        {
            if (env_allowed(e->string))
            {
                strcpy(p, e->string);
                p += strlen(e->string) + 1;
            }
            if (strncmp(e->string, "PATH=", 5 ) == 0)
            {
                path_seen = true;
            }
        }

        /* make sure PATH is set */
        if (!path_seen)
        {
            msg( M_INFO, "env_block: add %s", force_path );
            strcpy( p, force_path );
            p += strlen(force_path) + 1;
        }

        *p = '\0';
        return ret;
    }
    else
    {
        return NULL;
    }
}
开发者ID:benjdag,项目名称:openvpn,代码行数:60,代码来源:win32.c


示例3: argv_system_str_append

static void
argv_system_str_append (struct argv *a, const char *str, const bool enquote)
{
  if (str)
    {
      char *newstr;

      /* compute length of new system_str */
      size_t l = strlen (str) + 1; /* space for new string plus trailing '\0' */
      if (a->system_str)
	l += strlen (a->system_str) + 1; /* space for existing string + space (" ") separator */
      if (enquote)
	l += 2; /* space for two quotes */

      /* build new system_str */
      newstr = (char *) malloc (l);
      newstr[0] = '\0';
      check_malloc_return (newstr);
      if (a->system_str)
	{
	  strcpy (newstr, a->system_str);
	  strcat (newstr, " ");
	}
      if (enquote)
	strcat (newstr, "\"");
      strcat (newstr, str);
      if (enquote)
	strcat (newstr, "\"");
      free (a->system_str);
      a->system_str = newstr;
    }
}
开发者ID:huamichaelchen,项目名称:openvpn,代码行数:32,代码来源:misc.c


示例4: hmac_ctx_new

HMAC_CTX *
hmac_ctx_new(void)
{
    HMAC_CTX *ctx = HMAC_CTX_new();
    check_malloc_return(ctx);
    return ctx;
}
开发者ID:lstipakov,项目名称:openvpn,代码行数:7,代码来源:crypto_openssl.c


示例5: cipher_ctx_new

cipher_ctx_t *
cipher_ctx_new(void)
{
    EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
    check_malloc_return(ctx);
    return ctx;
}
开发者ID:lstipakov,项目名称:openvpn,代码行数:7,代码来源:crypto_openssl.c


示例6: pkcs11_get_x509_cert

static bool
pkcs11_get_x509_cert(pkcs11h_certificate_t pkcs11_cert, mbedtls_x509_crt *cert)
{
    unsigned char *cert_blob = NULL;
    size_t cert_blob_size = 0;
    bool ret = false;

    if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, NULL,
                                               &cert_blob_size) != CKR_OK)
    {
        msg(M_WARN, "PKCS#11: Cannot retrieve certificate object size");
        goto cleanup;
    }

    check_malloc_return((cert_blob = calloc(1, cert_blob_size)));
    if (pkcs11h_certificate_getCertificateBlob(pkcs11_cert, cert_blob,
                                               &cert_blob_size) != CKR_OK)
    {
        msg(M_WARN, "PKCS#11: Cannot retrieve certificate object");
        goto cleanup;
    }

    if (!mbed_ok(mbedtls_x509_crt_parse(cert, cert_blob, cert_blob_size)))
    {
        msg(M_WARN, "PKCS#11: Could not parse certificate");
        goto cleanup;
    }

    ret = true;
cleanup:
    free(cert_blob);
    return ret;
}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:33,代码来源:pkcs11_mbedtls.c


示例7: string_alloc

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;
}
开发者ID:alshalan,项目名称:Mobile-OpenVPN,代码行数:33,代码来源:buffer.c


示例8: md_ctx_new

EVP_MD_CTX *
md_ctx_new(void)
{
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    check_malloc_return(ctx);
    return ctx;
}
开发者ID:lstipakov,项目名称:openvpn,代码行数:7,代码来源:crypto_openssl.c


示例9: wide_cmd_line

static WCHAR *
wide_cmd_line(const struct argv *a, struct gc_arena *gc)
{
    size_t nchars = 1;
    size_t maxlen = 0;
    size_t i;
    struct buffer buf;
    char *work = NULL;

    if (!a)
    {
        return NULL;
    }

    for (i = 0; i < a->argc; ++i)
    {
        const char *arg = a->argv[i];
        const size_t len = strlen(arg);
        nchars += len + 3;
        if (len > maxlen)
        {
            maxlen = len;
        }
    }

    work = gc_malloc(maxlen + 1, false, gc);
    check_malloc_return(work);
    buf = alloc_buf_gc(nchars, gc);

    for (i = 0; i < a->argc; ++i)
    {
        const char *arg = a->argv[i];
        strcpy(work, arg);
        string_mod(work, CC_PRINT, CC_DOUBLE_QUOTE|CC_CRLF, '_');
        if (i)
        {
            buf_printf(&buf, " ");
        }
        if (string_class(work, CC_ANY, CC_SPACE))
        {
            buf_printf(&buf, "%s", work);
        }
        else
        {
            buf_printf(&buf, "\"%s\"", work);
        }
    }

    return wide_string(BSTR(&buf), gc);
}
开发者ID:benjdag,项目名称:openvpn,代码行数:50,代码来源:win32.c


示例10: lzo_compress_init

static void
lzo_compress_init(struct compress_context *compctx)
{
    msg(D_INIT_MEDIUM, "LZO compression initializing");
    ASSERT(!(compctx->flags & COMP_F_SWAP));
    compctx->wu.lzo.wmem_size = LZO_WORKSPACE;

    int lzo_status = lzo_init();
    if (lzo_status != LZO_E_OK)
    {
        msg(M_FATAL, "Cannot initialize LZO compression library (lzo_init() returns %d)", lzo_status);
    }
    compctx->wu.lzo.wmem = (lzo_voidp) lzo_malloc(compctx->wu.lzo.wmem_size);
    check_malloc_return(compctx->wu.lzo.wmem);
}
开发者ID:OpenVPN,项目名称:openvpn,代码行数:15,代码来源:lzo.c


示例11: do_setenv_x509

/* worker method for setenv_x509_track */
static void
do_setenv_x509 (struct env_set *es, const char *name, char *value, int depth)
{
  char *name_expand;
  size_t name_expand_size;

  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);
  check_malloc_return (name_expand);
  openvpn_snprintf (name_expand, name_expand_size, "X509_%d_%s", depth, name);
  setenv_str (es, name_expand, value);
  free (name_expand);
}
开发者ID:alonbl,项目名称:openvpn,代码行数:16,代码来源:ssl_verify_openssl.c


示例12: clone_buf

clone_buf (const struct buffer* buf)
#endif
{
  struct buffer ret;
  ret.capacity = buf->capacity;
  ret.offset = buf->offset;
  ret.len = buf->len;
#ifdef DMALLOC
  ret.data = (uint8_t *) openvpn_dmalloc (file, line, buf->capacity);
#else
  ret.data = (uint8_t *) malloc (buf->capacity);
#endif
  check_malloc_return (ret.data);
  memcpy (BPTR (&ret), BPTR (buf), BLEN (buf));
  return ret;
}
开发者ID:51isoft,项目名称:openvpn-ipv6,代码行数:16,代码来源:buffer.c


示例13: gc_addspecial

void gc_addspecial (void *addr, void (free_function)(void*), struct gc_arena *a)
{
  ASSERT(a);
  struct gc_entry_special *e;
#ifdef DMALLOC
  e = (struct gc_entry_special *) openvpn_dmalloc (file, line, sizeof (struct gc_entry_special));
#else
  e = (struct gc_entry_special *) malloc (sizeof (struct gc_entry_special));
#endif
  check_malloc_return (e);
  e->free_fnc = free_function;
  e->addr = addr;

  e->next = a->list_special;
  a->list_special = e;
}
开发者ID:746bce42110a11028656eca33867,项目名称:openvpn,代码行数:16,代码来源:buffer.c


示例14: env_block

static char *
env_block (const struct env_set *es)
{
  char * force_path = "PATH=C:\\Windows\\System32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem";

  if (es)
    {
      struct env_item *e;
      char *ret;
      char *p;
      size_t nchars = 1;
      bool path_seen = false;
      
      for (e = es->list; e != NULL; e = e->next)
	nchars += strlen (e->string) + 1;

      nchars += strlen(force_path)+1;

      ret = (char *) malloc (nchars);
      check_malloc_return (ret);

      p = ret;
      for (e = es->list; e != NULL; e = e->next)
	{
	  if (env_allowed (e->string))
	    {
	      strcpy (p, e->string);
	      p += strlen (e->string) + 1;
	    }
	  if ( strncmp(e->string, "PATH=", 5 ) == 0 )
	    path_seen = true;
	}

      /* make sure PATH is set */
      if ( !path_seen )
	{
	  msg( M_INFO, "env_block: add %s", force_path );
	  strcpy( p, force_path );
	  p += strlen(force_path) + 1;
	}

      *p = '\0';
      return ret;
    }
  else
    return NULL;
}
开发者ID:Acidburn0zzz,项目名称:openvpn,代码行数:47,代码来源:win32.c


示例15: x509_setenv

/*
 * Save X509 fields to environment, using the naming convention:
 *
 *  X509_{cert_depth}_{name}={value}
 */
void
x509_setenv (struct env_set *es, int cert_depth, openvpn_x509_cert_t *peer_cert)
{
  int i, n;
  int fn_nid;
  ASN1_OBJECT *fn;
  ASN1_STRING *val;
  X509_NAME_ENTRY *ent;
  const char *objbuf;
  unsigned char *buf;
  char *name_expand;
  size_t name_expand_size;
  X509_NAME *x509 = X509_get_subject_name (peer_cert);

  n = X509_NAME_entry_count (x509);
  for (i = 0; i < n; ++i)
    {
      ent = X509_NAME_get_entry (x509, i);
      if (!ent)
	continue;
      fn = X509_NAME_ENTRY_get_object (ent);
      if (!fn)
	continue;
      val = X509_NAME_ENTRY_get_data (ent);
      if (!val)
	continue;
      fn_nid = OBJ_obj2nid (fn);
      if (fn_nid == NID_undef)
	continue;
      objbuf = OBJ_nid2sn (fn_nid);
      if (!objbuf)
	continue;
      buf = (unsigned char *)1; /* bug in OpenSSL 0.9.6b ASN1_STRING_to_UTF8 requires this workaround */
      if (ASN1_STRING_to_UTF8 (&buf, val) <= 0)
	continue;
      name_expand_size = 64 + strlen (objbuf);
      name_expand = (char *) malloc (name_expand_size);
      check_malloc_return (name_expand);
      openvpn_snprintf (name_expand, name_expand_size, "X509_%d_%s", cert_depth,
	  objbuf);
      string_mod (name_expand, CC_PRINT, CC_CRLF, '_');
      string_mod ((char*)buf, CC_PRINT, CC_CRLF, '_');
      setenv_str (es, name_expand, (char*)buf);
      free (name_expand);
      OPENSSL_free (buf);
    }
}
开发者ID:alonbl,项目名称:openvpn,代码行数:52,代码来源:ssl_verify_openssl.c


示例16: argv_term

char *
argv_term (const char **f)
{
  const char *p = *f;
  const char *term = NULL;
  size_t termlen = 0;

  if (*p == '\0')
    return NULL;

  while (true)
    {
      const int c = *p;
      if (c == '\0')
	break;
      if (term)
	{
	  if (!isspace (c))
	    ++termlen;
	  else
	    break;
	}
      else
	{
	  if (!isspace (c))
	    {
	      term = p;
	      termlen = 1;
	    }
	}
      ++p;
    }
  *f = p;

  if (term)
    {
      char *ret;
      ASSERT (termlen > 0);
      ret = malloc (termlen + 1);
      check_malloc_return (ret);
      memcpy (ret, term, termlen);
      ret[termlen] = '\0';
      return ret;
    }
  else
    return NULL;
}
开发者ID:huamichaelchen,项目名称:openvpn,代码行数:47,代码来源:misc.c


示例17: full_clone_buf

/*
 *  This is exactly like clone_buf, but uses malloc to allocate the memory so that it can be cached
 *  properly
 */
struct buffer*
full_clone_buf(const struct buffer* buf)
{
  struct buffer* ret = (struct buffer*) malloc(sizeof(struct buffer));
  ret->capacity = buf->capacity;
  ret->offset = buf->offset;
  ret->len = buf->len;
#ifdef DMALLOC
  ret->data = (uint8_t *) openvpn_dmalloc (file, line, buf->capacity);
#else
  ret->data = (uint8_t *) malloc (buf->capacity);
#endif
  check_malloc_return (ret->data);
  memcpy (BPTR (ret), BPTR (buf), BLEN (buf));
  return ret;
  
}
开发者ID:alshalan,项目名称:Mobile-OpenVPN,代码行数:21,代码来源:buffer.c


示例18: prng_init

void
prng_init (const char *md_name, const int nonce_secret_len_parm)
{
  prng_uninit ();
  nonce_md = md_name ? md_kt_get (md_name) : NULL;
  if (nonce_md)
    {
      ASSERT (nonce_secret_len_parm >= NONCE_SECRET_LEN_MIN && nonce_secret_len_parm <= NONCE_SECRET_LEN_MAX);
      nonce_secret_len = 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);
	check_malloc_return (nonce_data);
	prng_reset_nonce();
      }
    }
}
开发者ID:KatekovAnton,项目名称:iOS-OpenVPN-Sample,代码行数:18,代码来源:crypto.c


示例19: alloc_buf

alloc_buf (size_t size)
#endif
{
  struct buffer buf;

  if (!buf_size_valid (size))
    buf_size_error (size);
  buf.capacity = (int)size;
  buf.offset = 0;
  buf.len = 0;
#ifdef DMALLOC
  buf.data = openvpn_dmalloc (file, line, size);
#else
  buf.data = calloc (1, size);
#endif
  check_malloc_return(buf.data);

  return buf;
}
开发者ID:alshalan,项目名称:Mobile-OpenVPN,代码行数:19,代码来源:buffer.c


示例20: buffer_list_aggregate_separator

void
buffer_list_aggregate_separator (struct buffer_list *bl, const size_t max, const char *sep)
{
  int sep_len = strlen(sep);

  if (bl->head)
    {
      struct buffer_entry *more = bl->head;
      size_t size = 0;
      int count = 0;
      for (count = 0; more && size <= max; ++count)
	{
	  size += BLEN(&more->buf) + sep_len;
	  more = more->next;
	}

      if (count >= 2)
	{
	  int i;
	  struct buffer_entry *e = bl->head, *f;

	  ALLOC_OBJ_CLEAR (f, struct buffer_entry);
	  f->buf.data = malloc (size);
	  check_malloc_return (f->buf.data);
	  f->buf.capacity = size;
	  for (i = 0; e && i < count; ++i)
	    {
	      struct buffer_entry *next = e->next;
	      buf_copy (&f->buf, &e->buf);
	      buf_write(&f->buf, sep, sep_len);
	      free_buf (&e->buf);
	      free (e);
	      e = next;
	    }
	  bl->head = f;
	  f->next = more;
	  if (!more)
	    bl->tail = f;
	}
    }
}
开发者ID:746bce42110a11028656eca33867,项目名称:openvpn,代码行数:41,代码来源:buffer.c



注:本文中的check_malloc_return函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ check_mem函数代码示例发布时间:2022-05-30
下一篇:
C++ check_malloc函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap