From ad9665560597a473774ea19dc87a40aef02090b3 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Sun, 3 Oct 2021 20:15:37 -0400 Subject: [PATCH] fix: replace free() with std::free() (#3321) * Disambiguate free() to use std::free() * Add cstdlib include --- include/pybind11/pybind11.h | 5 +++-- tests/test_embed/test_interpreter.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 16535f195..370e52cff 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -16,6 +16,7 @@ #include "detail/class.h" #include "detail/init.h" +#include #include #include #include @@ -1536,7 +1537,7 @@ public: char *doc_prev = rec_fget->doc; /* 'extra' field may include a property-specific documentation string */ detail::process_attributes::init(extra..., rec_fget); if (rec_fget->doc && rec_fget->doc != doc_prev) { - free(doc_prev); + std::free(doc_prev); rec_fget->doc = PYBIND11_COMPAT_STRDUP(rec_fget->doc); } } @@ -1544,7 +1545,7 @@ public: char *doc_prev = rec_fset->doc; detail::process_attributes::init(extra..., rec_fset); if (rec_fset->doc && rec_fset->doc != doc_prev) { - free(doc_prev); + std::free(doc_prev); rec_fset->doc = PYBIND11_COMPAT_STRDUP(rec_fset->doc); } if (! rec_active) rec_active = rec_fset; diff --git a/tests/test_embed/test_interpreter.cpp b/tests/test_embed/test_interpreter.cpp index fae14f751..20bcade0a 100644 --- a/tests/test_embed/test_interpreter.cpp +++ b/tests/test_embed/test_interpreter.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -315,7 +316,7 @@ TEST_CASE("sys.argv gets initialized properly") { { char *argv[] = {strdup("a.out")}; py::scoped_interpreter argv_scope(true, 1, argv); - free(argv[0]); + std::free(argv[0]); auto module = py::module::import("test_interpreter"); auto py_widget = module.attr("DerivedWidget")("The question"); const auto &cpp_widget = py_widget.cast();