Skip to content

Commit 1c9ab2e

Browse files
committed
libdrgn: dwarf_index: fix leak of DWARF index entries on failure
We're forgetting to unchain new entries which are chained on old entries.
1 parent 996d309 commit 1c9ab2e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

libdrgn/dwarf_index.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,9 @@ static struct drgn_error *index_cus(struct drgn_dwarf_index *dindex,
15891589

15901590
for (i = 0; i < ARRAY_SIZE(dindex->shards); i++) {
15911591
struct drgn_dwarf_index_shard *shard;
1592+
struct drgn_dwarf_index_die *die;
15921593
struct drgn_dwarf_index_die_map_iterator it;
1594+
size_t index;
15931595

15941596
shard = &dindex->shards[i];
15951597

@@ -1600,8 +1602,6 @@ static struct drgn_error *index_cus(struct drgn_dwarf_index *dindex,
16001602
* update.
16011603
*/
16021604
while (shard->dies.size) {
1603-
struct drgn_dwarf_index_die *die;
1604-
16051605
die = &shard->dies.data[shard->dies.size - 1];
16061606
if (die->file->failed)
16071607
shard->dies.size--;
@@ -1610,11 +1610,19 @@ static struct drgn_error *index_cus(struct drgn_dwarf_index *dindex,
16101610
}
16111611

16121612
/*
1613-
* We also need to delete those dies in the map. Note
1614-
* that any dies chained on the dies we delete must have
1615-
* also been added for this update, so there's no need
1616-
* to preserve them.
1613+
* The new entries may be chained off of existing
1614+
* entries; unchain them. Note that any entries chained
1615+
* off of the new entries must also be new, so there's
1616+
* no need to preserve them.
16171617
*/
1618+
for (index = 0; index < shard->dies.size; i++) {
1619+
die = &shard->dies.data[index];
1620+
if (die->next != SIZE_MAX &&
1621+
die->next >= shard->dies.size)
1622+
die->next = SIZE_MAX;
1623+
}
1624+
1625+
/* Finally, delete the new entries in the map. */
16181626
for (it = drgn_dwarf_index_die_map_first(&shard->map);
16191627
it.entry; ) {
16201628
if (it.entry->value >= shard->dies.size) {

0 commit comments

Comments
 (0)