I am trying to get into C and as a training example, I decided to write a simple dynamically sized list. But I am facing a weird problem, where the code only works up to an initial list size of 4. Starting at List size 5, I get an error.

```
typedef struct {
    int* data;
    int alloc_size;
    int length;
} List;

List create(int init_size) {
    List out;
    out.data = (int*) malloc(init_size * sizeof(int));
    out.alloc_size = init_size;
    out.length = 0;
    return out;
}

void list_push(List* list, int elem) {
    if (list->length == list->alloc_size) {
        list->data = (int*) realloc(list->data, 2 * list->alloc_size);
        list->alloc_size *= 2;
    }
    *(list->data + list->length) = elem;
    list->length++;
}

int list_pop(List* list) {
    list->length--;
    return *(list->data + list->length);
}

int main() {

    List list = create(5);

    for (int i = 0; i < 100; i++) {
        list_push(&list, i);
    }

    while (list.length > 0) {
        printf("%d\n", list_pop(&list));
    }

    return 0;
}

```

Up to `create(4)`, everything works as expected. But if the list is created with `create(5)` (i.e. an initial size of 5), I get the following error: `malloc: Incorrect checksum for freed object 0x7f7ff5c01778: probably modified after being freed. Corrupt value: 0x700000006`. I can't really wrap my head around what would cause this to only work up to specific initial sizes, as the list size is dynamically reallocated anyway.