Skip to content

doSetWithDirty fails to initialize refCount after calling allocNode #319

@abio-arista

Description

@abio-arista

Function doSetWithDirty calls allocNode to allocate a new VNode. After allocation, copyInsert initializes the items array of the node as expected. However, the refCount field of the VNode is not initialized, leaving it with an undefined value.

This results in uninitialized memory being read later in releaseNode, which triggers Valgrind:

Conditional jump or move depends on uninitialised value(s)
==213196==    at 0x20B87E90: releaseNode (pvectorcmodule.c:204)
==213196==    by ...
==213196== Uninitialised value was created by a heap allocation
==213196==    at 0x48680F8: malloc (vg_replace_malloc.c:381)
==213196==    by 0x20B8914B: allocNode (pvectorcmodule.c:94)
==213196==    by 0x20B8914B: allocNode (pvectorcmodule.c:88)
==213196==    by 0x20B8914B: doSetWithDirty (pvectorcmodule.c:1360)
==213196==    by 0x20B892E7: PVectorEvolver_set_item (pvectorcmodule.c:1468)
==213196==    by ...

The Valgrind warning disappears if refCount is initialized after the call to allocNode in doSetWithDirty, confirming that the uninitialized field is the root cause.

Note that other calls to allocNode, newNode and copyNode, properly initialize the returned VNode.

A suggested fix is to initialize resultNode->refCount in doSetWithDirty after calling allocNode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions