mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-30 05:11:14 +00:00
Refine memory management (#579)
- Added one macro to avoid dangling pointers - Added two functions to perform NULL pointer check since the allocation is not guaranteed by C library, although it is a rare case, just for sanity - Add NULL pointer check to brealloc() and bfree() and for sanity as well Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
+3
-2
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
|
||||
#include "json.h"
|
||||
#include "mm-wrapper.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
@@ -90,12 +91,12 @@ typedef struct {
|
||||
|
||||
static void *default_alloc(size_t size, int zero, void *user_data)
|
||||
{
|
||||
return zero ? calloc(1, size) : malloc(size);
|
||||
return zero ? calloc(1, size) : SS_SAFEMALLOC(size);
|
||||
}
|
||||
|
||||
static void default_free(void *ptr, void *user_data)
|
||||
{
|
||||
free(ptr);
|
||||
SS_SAFEFREE(ptr);
|
||||
}
|
||||
|
||||
static void *json_alloc(json_state *state, unsigned long size, int zero)
|
||||
|
||||
Reference in New Issue
Block a user