1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00
stedolan-jq/jv_alloc.c
Stephen Dolan 8dca3ef10d 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)'
2012-12-18 17:01:23 +00:00

29 lines
435 B
C

#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) {
void* p = malloc(sz);
if (!p) {
memory_exhausted();
}
return p;
}
void jv_mem_free(void* p) {
free(p);
}
void* jv_mem_realloc(void* p, size_t sz) {
p = realloc(p, sz);
if (!p) {
memory_exhausted();
}
return p;
}