Skip to content

Would SWIG example normalize_numpy leak memory? #49

Description

@adamryczkowski

Here's a quote from the wrapper in bindings_swig/bingins.i:

    void normalize_numpy(double* in_1, unsigned size_in_1,
                         double** out_1, int* size_out_1)
    {
        const std::vector<double> vector(in_1, in_1 + size_in_1);

        auto result = mymath::normalize(vector);

        *out_1 = static_cast<double*>(malloc(result.size() * sizeof(double)));
        std::copy(result.begin(), result.end(), *out_1);

        *size_out_1 = result.size();
    }

I can see malloc. The question is when the vector is going to be deallocated on the Python side? Or would numpy do it implicitly (perhaps using Python's GC)?

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