Skip to content

Memory leak in dart:ffi samples #93

Closed
@xzfc

Description

@xzfc

Here the memory is allocated in reverse():

char *reversed_str = (char *)malloc((length + 1) * sizeof(char));

Here it used in toDartString():

final reversedMessage =
reverse(backwards.toNativeUtf8(), backwards.length).toDartString();

It is not clear how the allocated memory should be freed.

Should it be done using malloc.free() call or there is a more conventional way to do it in dart? OTOH, if toDartString() actually takes ownership for this C string and there is no memory leak, then this behavior should be documented somewhere.

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