Skip to content

(benign?) memory leak in unused branch of HM_HH_freeAllDependants? #229

@shwestrick

Description

@shwestrick

I believe there is a space leak in the else branch here:

if (retireInsteadOfFree) {
HH_EBR_retire(s, child);
} else {
freeFixedSize(myUFAllocator, child);
}

The space leak is never materializing because at the moment this branch is unused. HM_HH_freeAllDependants is called in exactly two places, both with retireInsteadOfFree=TRUE.

(We're essentially seeing an artifact of a previous memory management strategy.)

Some background:
Every union-find node has an HH struct as a payload, and the HH struct also needs to be freed. For example, when EBR eventually frees a union-find node, the corresponding payload is also freed:

void freeUnionFind (GC_state s, void *ptr) {
HM_UnionFindNode hufp = (HM_UnionFindNode)ptr;
assert(hufp->payload != NULL);
freeFixedSize(getHHAllocator(s), hufp->payload);
freeFixedSize(getUFAllocator(s), hufp);
}

Presumably, the fix should be as simple as adding the line freeFixedSize(getHHAllocator(s), child->payload) to the else branch highlighted at the top of the issue... but it's not easy to test, because of the unused branch. Perhaps a better fix would be to put a mandatory crash with DIE(...) in the else branch to mark it for future inspection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions