Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Protect malloc_usable size from NULL pointers that may cause it to ex…

…plode.
  • Loading branch information...
commit 3fc86674f589f406ba21df6b0d3ab0bcc726f6eb 1 parent 965cc23
Joe Damato authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 ext/tracers/memory.c
16 ext/tracers/memory.c
View
@@ -42,7 +42,9 @@ malloc_tramp(size_t size)
stats.malloc_bytes_requested += size;
stats.malloc_calls++;
- stats.malloc_bytes_actual += malloc_usable_size(ret);
+
+ if (ret)
+ stats.malloc_bytes_actual += malloc_usable_size(ret);
errno = err;
return ret;
@@ -59,7 +61,9 @@ calloc_tramp(size_t nmemb, size_t size)
stats.calloc_bytes_requested += (nmemb * size);
stats.calloc_calls++;
- stats.calloc_bytes_actual += malloc_usable_size(ret);
+
+ if (ret)
+ stats.calloc_bytes_actual += malloc_usable_size(ret);
errno = err;
return ret;
@@ -76,7 +80,9 @@ realloc_tramp(void *ptr, size_t size)
stats.realloc_bytes_requested += size;
stats.realloc_calls++;
- stats.realloc_bytes_actual += malloc_usable_size(ret);
+
+ if (ret)
+ stats.realloc_bytes_actual += malloc_usable_size(ret);
errno = err;
return ret;
@@ -85,7 +91,9 @@ realloc_tramp(void *ptr, size_t size)
static void
free_tramp(void *ptr)
{
- stats.free_bytes_actual += malloc_usable_size(ptr);
+ if (ptr)
+ stats.free_bytes_actual += malloc_usable_size(ptr);
+
stats.free_calls++;
free(ptr);
Please sign in to comment.
Something went wrong with that request. Please try again.