Otherwise we could have a failure followed by a smaller write that
succeeds and get a corrupted blob. If we ever OOM, we should stop.
v2 (Jason Ekstrand):
- Initialize the new boolean member in create_blob
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: mesa-stable@lists.freedesktop.org
size_t to_allocate;
uint8_t *new_data;
+ if (blob->out_of_memory)
+ return false;
+
if (blob->size + additional <= blob->allocated)
return true;
to_allocate = MAX2(to_allocate, blob->allocated + additional);
new_data = realloc(blob->data, to_allocate);
- if (new_data == NULL)
+ if (new_data == NULL) {
+ blob->out_of_memory = true;
return false;
+ }
blob->data = new_data;
blob->allocated = to_allocate;
blob->data = NULL;
blob->allocated = 0;
blob->size = 0;
+ blob->out_of_memory = false;
return blob;
}
/** The number of bytes that have actual data written to them. */
size_t size;
+
+ /**
+ * True if we've ever failed to realloc or if we go pas the end of a fixed
+ * allocation blob.
+ */
+ bool out_of_memory;
};
/* When done reading, the caller can ensure that everything was consumed by