Return failure rather than abort()ing on out-of-memory conditions. #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this change, nestegg was verified to fail cleanly (without crashes,
invalid memory accesses, or memory leaks) for allocation failures at any
stage of processing for a simple WebM stream, using roughly:
int malloc_counter;
void _realloc(void *ptr, size_t size) {
if (--malloc_counter < 0) return NULL;
return real_realloc(ptr, size); // the libc realloc()
}
void *malloc(size_t size) {return realloc(NULL, size);}
void *calloc(size_t nmemb, size_t size) {
void ptr = malloc(nmemb_size);
if (ptr) memset(ptr, 0, nmembsize);
return ptr;
}
for (int i = 0; i < 10000; i++) {
malloc_counter = i;
nestegg ctx;
if (nestegg_init(&ctx, ...) != 0) continue;
if (nestegg_read_packet(&ctx, ...) > 0) break;
nestegg_destroy(&ctx);
}
assert(i < 10000);