1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Print an error message and abort in out-of-memory situations.

Closes #43.

Tested with:

    ulimit -v 5000
    ./jq -n -c 'def f(x): x,f([x,x]); f(0)'
This commit is contained in:
Stephen Dolan
2012-12-18 17:01:23 +00:00
parent 04daafbde3
commit 8dca3ef10d

View File

@ -1,9 +1,18 @@
#include <stdlib.h>
#include <stdio.h>
#include "jv_alloc.h"
static void memory_exhausted() {
fprintf(stderr, "error: cannot allocate memory\n");
abort();
}
void* jv_mem_alloc(size_t sz) {
return malloc(sz);
void* p = malloc(sz);
if (!p) {
memory_exhausted();
}
return p;
}
void jv_mem_free(void* p) {
@ -11,5 +20,9 @@ void jv_mem_free(void* p) {
}
void* jv_mem_realloc(void* p, size_t sz) {
return realloc(p, sz);
p = realloc(p, sz);
if (!p) {
memory_exhausted();
}
return p;
}