Skip to content

Potential dangling pointer with af_get_default_random_engine() #2940

@cschreib-ibex

Description

@cschreib-ibex

af_get_default_random_engine() returns a handle to a thread_local RandomEngine object. From what I understand of the implementation, calling af_release_random_engine() would delete the RandomEngine, and any future call to af_get_default_random_engine() would then return the same handle, which is now dangling (references a deleted object).

In fact, whenever af_get_default_random_engine() is used internally in ArrayFire, I see that af_release_random_engine() is never called. Likewise, the C++ API actually makes a copy of the returned handle, so the original default engine doesn't get deleted.

If this is intended, it may be worth mentioning this special case in the documentation of either af_get_default_random_engine() or af_get_default_random_engine() (or both).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions