added double free detection

This commit is contained in:
Fufu Fang 2021-08-31 11:54:42 +01:00
parent e02042cade
commit 04212c3d55
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
1 changed files with 7 additions and 3 deletions

View File

@ -133,15 +133,19 @@ void *CALLOC(size_t nmemb, size_t size)
{ {
void *ptr = calloc(nmemb, size); void *ptr = calloc(nmemb, size);
if (!ptr) { if (!ptr) {
lprintf(fatal, "calloc() failed, %s!\n", strerror(errno)); lprintf(fatal, "%s!\n", strerror(errno));
} }
return ptr; return ptr;
} }
void FREE(void *ptr) void FREE(void *ptr)
{ {
if (ptr) {
free(ptr); free(ptr);
ptr = NULL; ptr = NULL;
} else {
lprintf(fatal, "attempted to double free a pointer!\n");
}
} }
char *str_to_hex(char *s) char *str_to_hex(char *s)