mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Add a memory test at the stream buffer
This commit is contained in:
parent
fed3e8be1f
commit
87aa5d5e7b
2 changed files with 19 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue