C语言 码拜 6年前 (2015-07-10) 537次浏览 0个评论

NULL指针可以FREE多次吗 为什么; NULL指针可以FREE多次吗 为什么

当然可以。 The free function


#include <stdlib.h>
void free(void *ptr);


The free function causes the space pointed to by ptr to be
deallocated, that is, made available for further allocation. If ptr
is a null pointer, no action occurs.
Otherwise, if the argument does
not match a pointer earlier returned by the calloc , malloc , or
realloc function, or if the space has been deallocated by a call to
free or realloc , the behavior is undefined.


The free function returns no value.


C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\free.c

*free.c - free an entry in the heap
*       Copyright (c) Microsoft Corporation. All rights reserved.
*       Defines the following functions:
*           free()     - free a memory block in the heap

#include <cruntime.h>
#include <malloc.h>
#include <winheap.h>
#include <windows.h>
#include <internal.h>
#include <mtdll.h>
#include <dbgint.h>
#include <rtcsup.h>

*void free(pblock) - free a block in the heap
*       Free a memory block in the heap.
*       Special ANSI Requirements:
*       (1) free(NULL) is benign.
*       void *pblock - pointer to a memory block in the heap
*       <void>

void __cdecl _free_base (void * pBlock)

        int retval = 0;

        if (pBlock == NULL)

        RTCCALLBACK(_RTC_Free_hook, (pBlock, 0));

        retval = HeapFree(_crtheap, 0, pBlock);
        if (retval == 0)
            errno = _get_errno_from_oserr(GetLastError());

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明NULL指针是否可以FREE多次?为什么
喜欢 (0)
分享 (0)