浏览代码

fix malloc_usable_size for NULL input

the linux man page specifies malloc_usable_size(0) to return 0 and
this is the semantics other implementations follow (jemalloc).
reported by Alexander Monakov.
Szabolcs Nagy 9 年之前
父节点
当前提交
d150764697
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      src/malloc/malloc_usable_size.c

+ 1 - 1
src/malloc/malloc_usable_size.c

@@ -13,5 +13,5 @@ struct chunk {
 
 size_t malloc_usable_size(void *p)
 {
-	return CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD;
+	return p ? CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD : 0;
 }