Add a memory test at the stream buffer

This commit is contained in:
Andrea Mazzoleni 2015-02-18 19:17:48 +01:00
parent fed3e8be1f
commit 87aa5d5e7b
2 changed files with 19 additions and 3 deletions

View file

@ -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) {

View file

@ -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.