Skip to content

Bug: malloc issues in python wrapper #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 of 3 tasks
beviah opened this issue Feb 14, 2025 · 0 comments
Open
2 of 3 tasks

Bug: malloc issues in python wrapper #569

beviah opened this issue Feb 14, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@beviah
Copy link

beviah commented Feb 14, 2025

Describe the bug

trace is quite long, but seems many originate here

py::enum_<metric_punned_signature_t>(m, "MetricSignature")
    .value("ArrayArray", metric_punned_signature_t::array_array_k)
    .value("ArrayArraySize", metric_punned_signature_t::array_array_size_k);

==3173479== HEAP SUMMARY:
==3173479== in use at exit: 2,026,556 bytes in 1,523 blocks
==3173479== total heap usage: 21,861 allocs, 20,338 frees, 28,825,491 bytes allocated
==3173479==
==3173479== 1 bytes in 1 blocks are still reachable in loss record 1 of 723
==3173479== at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3173479== by 0x587976: PyMem_Malloc (in /usr/bin/python3.12)
==3173479== by 0x582E89: PyModule_ExecDef (in /usr/bin/python3.12)
==3173479== by 0x5FDEE6: ??? (in /usr/bin/python3.12)
==3173479== by 0x5822A1: ??? (in /usr/bin/python3.12)
==3173479== by 0x5DBA02: PyEval_EvalFrameDefault (in /usr/bin/python3.12)
==3173479== by 0x549FF6: ??? (in /usr/bin/python3.12)
==3173479== by 0x54B882: PyObject_CallMethodObjArgs (in /usr/bin/python3.12)
==3173479== by 0x5FE2E4: PyImport_ImportModuleLevelObject (in /usr/bin/python3.12)
==3173479== by 0x5DCCDF: PyEval_EvalFrameDefault (in /usr/bin/python3.12)
==3173479== by 0x5D5E4A: PyEval_EvalCode (in /usr/bin/python3.12)
==3173479== by 0x5D39DB: ??? (in /usr/bin/python3.12)
==3173479==
==3173479== 1 bytes in 1 blocks are still reachable in loss record 2 of 723
==3173479== at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3173479== by 0x4A4835E: strdup (strdup.c:42)
==3173479== by 0xA972A04F: operator() (pybind11.h:356)
==3173479== by 0xA972A04F: pybind11::cpp_function::initialize_generic(std::unique_ptr<pybind11::detail::function_record, pybind11::cpp_function::Init
ializingFunctionRecordDeleter>&&, char const*, std::type_info const* const*, unsigned long) (pybind11.h:386)
==3173479== by 0xA9753AE7: initialize<const pybind11::enum
unum::usearch::metric_punned_signature_t::enum
<>(const pybind11::handle&, char const*):
:<lambda(unum::usearch::metric_punned_signature_t)>&, int, unum::usearch::metric_punned_signature_t> (pybind11.h:328)
==3173479== by 0xA9753AE7: cpp_function<const pybind11::enum_unum::usearch::metric_punned_signature_t::enum_<>(const pybind11::handle&, char const*
)::<lambda(unum::usearch::metric_punned_signature_t)>&> (pybind11.h:127)
==3173479== by 0xA9753AE7: def_property_readonly<pybind11::enum_unum::usearch::metric_punned_signature_t::enum_<>(const pybind11::handle&, char con
st*)::<lambda(unum::usearch::metric_punned_signature_t)> > (pybind11.h:1753)
==3173479== by 0xA9753AE7: pybind11::enum_unum::usearch::metric_punned_signature_t::enum_<>(pybind11::handle const&, char const*) (pybind11.h:2238)
==3173479== by 0xA96DDE73: pybind11_init_compiled(pybind11::module_&) (lib.cpp:977)
==3173479== by 0xA96E26CE: PyInit_compiled (lib.cpp:957)
==3173479== by 0x6A9D80: ??? (in /usr/bin/python3.12)
==3173479== by 0x6A94D1: ??? (in /usr/bin/python3.12)
==3173479== by 0x582426: ??? (in /usr/bin/python3.12)
==3173479== by 0x5DBA02: PyEval_EvalFrameDefault (in /usr/bin/python3.12)
==3173479== by 0x549FF6: ??? (in /usr/bin/python3.12)
==3173479== by 0x54B882: PyObject_CallMethodObjArgs (in /usr/bin/python3.12)
==3173479==
==3173479== 1 bytes in 1 blocks are still reachable in loss record 3 of 723
==3173479== at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3173479== by 0x4A4835E: strdup (strdup.c:42)
==3173479== by 0xA972A04F: operator() (pybind11.h:356)
==3173479== by 0xA972A04F: pybind11::cpp_function::initialize_generic(std::unique_ptr<pybind11::detail::function_record, pybind11::cpp_function::Init
ializingFunctionRecordDeleter>&&, char const*, std::type_info const* const*, unsigned long) (pybind11.h:386)
==3173479== by 0xA9752FD7: initialize<const pybind11::enum
unum::usearch::metric_kind_t::enum_<>(const pybind11::handle&, char const*)::<lambda(unu
m::usearch::metric_kind_t)>&, unsigned char, unum::usearch::metric_kind_t> (pybind11.h:328)
==3173479== by 0xA9752FD7: cpp_function<const pybind11::enum_unum::usearch::metric_kind_t::enum_<>(const pybind11::handle&, char const*)::<lambda(u
num::usearch::metric_kind_t)>&> (pybind11.h:127)
==3173479== by 0xA9752FD7: def_property_readonly<pybind11::enum_unum::usearch::metric_kind_t::enum_<>(const pybind11::handle&, char const*)::<lambd
a(unum::usearch::metric_kind_t)> > (pybind11.h:1753)
==3173479== by 0xA9752FD7: pybind11::enum_unum::usearch::metric_kind_t::enum_<>(pybind11::handle const&, char const*) (pybind11.h:2238)
==3173479== by 0xA96DDEBA: pybind11_init_compiled(pybind11::module_&) (lib.cpp:981)
==3173479== by 0xA96E26CE: PyInit_compiled (lib.cpp:957)
==3173479== by 0x6A9D80: ??? (in /usr/bin/python3.12)
==3173479== by 0x6A94D1: ??? (in /usr/bin/python3.12)
==3173479== by 0x582426: ??? (in /usr/bin/python3.12)
==3173479== by 0x5DBA02: _PyEval_EvalFrameDefault (in /usr/bin/python3.12)
==3173479== by 0x549FF6: ??? (in /usr/bin/python3.12)
==3173479== by 0x54B882: PyObject_CallMethodObjArgs (in /usr/bin/python3.12)

Steps to reproduce

import numpy as np
from usearch.index import Index
num_vectors = 33
vector_dim = 128
vectors = np.random.rand(num_vectors, vector_dim).astype(np.float32)
index = Index(ndim=vector_dim)

for i in range(1,num_vectors):
    key = i*7
    index.add(key, vectors[i])
    if i == 25:
        example_index = key

query = vectors[25].reshape(1, -1)  # Convert to a 2D array
query[0][0] = 0.8
results = index.search(query, count=3)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes  python x.py > debug.log 2>&1

Expected behavior

I guess there should be no memory issues :)

USearch version

2.17.2

Operating System

Ubuntu 24.04.1 LTS

Hardware architecture

x86

Which interface are you using?

Python bindings

Contact Details

No response

Are you open to being tagged as a contributor?

  • I am open to being mentioned in the project .git history as a contributor

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@beviah beviah added the bug Something isn't working label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant