From: Junio C Hamano Date: Tue, 14 Apr 2026 20:08:39 GMT Subject: Re: [PATCH 1/8] t/helper: add 'test-tool bitmap write' subcommand Message-ID: In-Reply-To: Taylor Blau writes: > +struct bitmap_writer_data { > + struct packing_data packed; > + struct pack_idx_entry **index; > + uint32_t nr; > +}; > + > +static int add_packed_object(const struct object_id *oid, > + struct packed_git *pack, > + uint32_t pos, > + void *_data) > +{ > + struct bitmap_writer_data *data = _data; > + struct object_entry *entry; > + struct object_info oi = OBJECT_INFO_INIT; > + enum object_type type; > + > + oi.typep = &type; > + > + entry = packlist_alloc(&data->packed, oid); data->packed is "packing data" that has a pointer "objects" that is a flat array of "struct object_entry". This array is dynamically expanded with realloc() in packlist_alloc(), and it returns a pointer into this data->packed->objects[] array. We receive it in a local variable "entry" here. > + entry->idx.offset = nth_packed_object_offset(pack, pos); > + if (packed_object_info(pack, entry->idx.offset, &oi) < 0) > + die("could not get type of object %s", > + oid_to_hex(oid)); > + oe_set_type(entry, type); > + oe_set_in_pack(&data->packed, entry, pack); And populate the entry. > + data->index[data->nr++] = &entry->idx; And then store the pointer to one of the members (actually the first member) in that "struct object_entry" instance in that data->packed->objects[] array we took from. What happens when a repeated call to this function to add many objects (those contained within the pack we are iterating over) caused the packlist_alloc() to realloc data->packed->objects[] array eventually? Wouldn't it invalidate the address of &entry->idx we are taking from before the realloc() happens? I must be missing something?