ADDING FEC - fix when the end block of the heap was split
@@ -68,9 +68,9 @@ meta_data *find_slot(protoop_plugin_t *p, unsigned int size) {
* If a free slot can accommodate atleast 1 more (METADATA_SIZE + ALIGNMENT FACTOR)
* apart from the requested size, then the slot is divided to save space.
*/
-void divide_slot(void *slot, unsigned int size) {
+void divide_slot(protoop_plugin_t *p, void *slot, unsigned int size) {
meta_data *slot_to_divide = (meta_data *) slot;
- meta_data *new_slot= (meta_data*) ((char *) slot_to_divide + METADATA_SIZE + size);
+ meta_data *new_slot= (meta_data*) (((char *) slot_to_divide) + METADATA_SIZE + size);
new_slot->size=slot_to_divide->size - size - METADATA_SIZE;
new_slot->available = 1;
@@ -79,6 +79,9 @@ void divide_slot(void *slot, unsigned int size) {
slot_to_divide->size = size;
slot_to_divide->next_block = new_slot;
+ if (p && (char *) slot_to_divide == p->heap_last_block) {
+ p->heap_last_block = (char *) new_slot;
+ }
}
/**
@@ -130,7 +133,7 @@ void *my_malloc(picoquic_cnx_t *cnx, unsigned int size) {
slot = find_slot(p, size);
if (slot) {
if (((meta_data *) slot)->size > size + METADATA_SIZE) {
- divide_slot(slot, size);
+ divide_slot(p, slot, size);
}
} else {
slot = extend(p, size);
