diff --git a/cmdline/util.c b/cmdline/util.c index ef6d67e9..a62af390 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -81,7 +81,7 @@ STREAM* sopen_read(const char* file) } #endif - s->buffer = malloc_nofail(STREAM_SIZE); + s->buffer = malloc_nofail_test(STREAM_SIZE); s->pos = s->buffer; s->end = s->buffer; s->state = STREAM_STATE_READ; @@ -106,7 +106,7 @@ STREAM* sopen_multi_write(unsigned count) for (i = 0; i < count; ++i) s->handle[i].f = -1; - s->buffer = malloc_nofail(STREAM_SIZE); + s->buffer = malloc_nofail_test(STREAM_SIZE); s->pos = s->buffer; s->end = s->buffer + STREAM_SIZE; s->state = STREAM_STATE_WRITE; @@ -336,7 +336,7 @@ int sread(STREAM* f, void* void_data, unsigned size) sptrset(f, pos); } else { - /* standard version using sputc() */ + /* standard version using sgetc() */ while (size--) { int c = sgetc(f); if (c == EOF) { @@ -922,6 +922,17 @@ void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr) return ptr; } +void* malloc_nofail_test(size_t size) +{ + void* ptr; + + ptr = malloc_nofail(size); + + mtest_vector(1, size, &ptr); + + return ptr; +} + void mtest_vector(int n, size_t size, void** vv) { if (raid_mtest_vector(n, size, vv) != 0) { diff --git a/cmdline/util.h b/cmdline/util.h index 6867a027..d08b070c 100644 --- a/cmdline/util.h +++ b/cmdline/util.h @@ -403,6 +403,11 @@ void* malloc_nofail_align(size_t size, void** freeptr); */ void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr); +/** + * Safe allocation with memory test. + */ +void* malloc_nofail_test(size_t size); + /** * Tests the memory vector for RAM problems. * If a problem is found, it crashes.