wchar_t * __cdecl _wcsdup (
        const wchar_t * string
        )

#endif  /* _DEBUG */

{
        wchar_t *memory;
    size_t size = 0;

        if (!string)
                return(NULL);

    size = wcslen(string) + 1;
#ifdef _DEBUG
        if (memory = (wchar_t *) _calloc_dbg(size, sizeof(wchar_t), nBlockUse, szFileName, nLine))
#else  /* _DEBUG */
        if (memory = (wchar_t *) calloc(size, sizeof(wchar_t)))
#endif  /* _DEBUG */
        {
                _ERRCHECK(wcscpy_s(memory, size, string));
        return memory;
        }

        return(NULL);
}
Example #2
0
/**
  Allocate a sized block of memory.

  @param size   The size of the memory block in bytes.
  @param flags  Failure action modifiers (bitmasks).

  @return A pointer to the allocated memory block, or NULL on failure.
*/
static void *my_raw_malloc(size_t size, myf my_flags)
{
  void* point;
  DBUG_ENTER("my_raw_malloc");
  DBUG_PRINT("my",("size: %lu  my_flags: %d", (ulong) size, my_flags));

  /* Safety */
  if (!size)
    size=1;

#if defined(MY_MSCRT_DEBUG)
  if (my_flags & MY_ZEROFILL)
    point= _calloc_dbg(size, 1, _CLIENT_BLOCK, __FILE__, __LINE__);
  else
    point= _malloc_dbg(size, _CLIENT_BLOCK, __FILE__, __LINE__);
#else
  if (my_flags & MY_ZEROFILL)
    point= calloc(size, 1);
  else
    point= malloc(size);
#endif

  DBUG_EXECUTE_IF("simulate_out_of_memory",
                  {
                    free(point);
                    point= NULL;
                  });
Example #3
0
static Character* __cdecl common_tempnam(
    Character const* const alternative,
    Character const* const prefix,
    int              const block_use,
    char const*      const file_name,
    int              const line_number
    ) throw()
{
    // These are referenced only in the Debug CRT build
    UNREFERENCED_PARAMETER(block_use);
    UNREFERENCED_PARAMETER(file_name);
    UNREFERENCED_PARAMETER(line_number);

    typedef __acrt_stdio_char_traits<Character> stdio_traits;

    Character const* directory = nullptr;
    __crt_unique_heap_ptr<Character const> const directory_cleanup(get_directory(alternative, &directory));

    unsigned const prefix_length = prefix != nullptr
        ? static_cast<unsigned>(stdio_traits::tcslen(prefix))
        : 0;

    // The 12 allows for a backslash, a ten character temporary string, and a
    // null terminator.
    unsigned const buffer_size = static_cast<unsigned>(stdio_traits::tcslen(directory)) + prefix_length + 12;

    __crt_unique_heap_ptr<Character, __crt_public_free_policy> result(
            static_cast<Character*>(_calloc_dbg(
                buffer_size,
                sizeof(Character),
                block_use,
                file_name,
                line_number)));

    if (!result)
        return nullptr;

    *result.get() = 0;
    _ERRCHECK(stdio_traits::tcscat_s(result.get(), buffer_size, directory));

    if (__crt_stdio_path_requires_backslash(directory))
    {
        static Character const backslash[] = { '\\', '\0' };
        _ERRCHECK(stdio_traits::tcscat_s(result.get(), buffer_size, backslash));
    }

    if (prefix != nullptr)
    {
        _ERRCHECK(stdio_traits::tcscat_s(result.get(), buffer_size, prefix));
    }

    Character* const ptr = result.get() + stdio_traits::tcslen(result.get());
    size_t     const ptr_size = buffer_size - (ptr - result.get());

    if (!compute_name(result.get(), ptr, ptr_size, prefix_length))
        return nullptr;

    return result.detach();
}
Example #4
0
void* BioAPI _BioAPI_calloc(uint32 num, uint32 size, void* ref,
							const char * szFilename, uint32 u32LineNumber)
{
#ifdef _DEBUG
	return _calloc_dbg( num, size, _NORMAL_BLOCK, szFilename, u32LineNumber );
#else
	return calloc( num, size );
#endif
}
Example #5
0
void allocCalloc(bool bFree)
{
    int* leaked_memory = (int*)calloc(47, sizeof(int));
    int* leaked_memory_dbg = (int*)_calloc_dbg(39, sizeof(int), _NORMAL_BLOCK, __FILE__, __LINE__);
    if (bFree)
    {
        free(leaked_memory);
        _free_dbg(leaked_memory_dbg, _NORMAL_BLOCK);
    }
}
Example #6
0
static void *CallocCHK(size_t count, size_t size)
#endif
{
   unsigned long *p;
   unsigned char *tmp;

#if defined BLAK_PLATFORM_WINDOWS && !defined NDEBUG
   tmp = (unsigned char*)_calloc_dbg(count, (sizeof(unsigned long) * 3), _NORMAL_BLOCK, filename, linenumber);
#else
   tmp = (unsigned char *)calloc(count, size);
#endif


   if (tmp == NULL) {
      return NULL;
   }

   p = (unsigned long *)tmp;

#ifdef MDEBUG
   printf("Size Req: %d   Size Got: %d\n", count * size, count * (size + (sizeof(unsigned long) * 3)));
   printf("Block at: 0x%lx\n", p);
#endif

   /* store actual size of allocated block */
   p[0] = size;

   /* store our check token */
   p[1] = MCHK_START;

   p = (unsigned long*)(tmp + (count * (size + (sizeof(unsigned long) * 2))));

   p[0] = MCHK_END;

   tmp += 8;

#ifdef MDEBUG
   printf("End:      0x%lx \n", p);
   printf("Actual:   0x%lx \n", tmp);
#endif

   /*
   Charlie:
   Boundschecker 6.604 will complain about memory being leaked from this scope,
   its half right, if theres two messages about it, then it really is
   being leaked
   */
   return tmp;
}
Example #7
0
/*
 * A calloc() that fails if no memory. It's pretty hopeless to continue
 * this program if calloc() fails.
 */
void *calloc_at (size_t num, size_t size, const char *file, unsigned line)
{
  struct mem_head *head;

  size = (size * num) + sizeof(*head);

#if defined(_CRTDBG_MAP_ALLOC)     /* cl -MDd .. */
  head = _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
#else
  head = calloc (1, size);
#endif

  if (!head)
     FATAL ("calloc() failed at %s, line %u\n", file, line);

  head->marker = MEM_MARKER;
  head->size   = size;
  add_to_mem_list (head, file, line);
  mem_max += size;
  mem_allocs++;
  return (head+1);
}
Example #8
0
void *__cdecl _calloc_dbg_impl( size_t nNum, size_t nSize, int nBlockUse, 
	const char * szFileName, int nLine, int * errno_tmp )
{
	return _calloc_dbg( nNum, nSize, nBlockUse, szFileName, nLine );
}