あたっしゅ さんが書きました: ↑3年前
やっぱ、static int* a; を free(a); しちゃ、まずいだろ。
static int* a;はヌルポインタに初期化され、
freeにヌルポインタを渡した場合は何もしないと決まっているので、問題ないはずです。
また、#6ではmallocに0を渡しているようですが、malloc(0)が何を返すかは処理系定義です。
#6の例では、malloc(0)はヌルポインタではないポインタを返すタイプの処理系であり、
その返されたポインタをfreeしていないため、メモリリークの発生として検出されているようですね。
以下、
N1570より引用
6.7.9 Initialization
If an object that has static or thread storage duration is not initialized
explicitly, then:
— if it has pointer type, it is initialized to a null pointer;
7.22.3.3 The free function
If ptr is a null pointer, no action occurs.
J.3 Implementation-defined behavior
J.3.12 Library functions
Whether the calloc, malloc, and realloc functions return a null pointer or a
pointer to an allocated object when the size requested is zero (7.22.3).
7.22.3 Memory management functions
If the size of
the space requested is zero, the behavior is implementation-defined: either a null pointer
is returned, or the behavior is as if the size were some nonzero value, except that the
returned pointer shall not be used to access an object.