Skip to content

[BUG]: free(): invalid pointer #4137

Description

@whybeyoung

Required prerequisites

Problem description

Like issue #1472,
we still have problem in 2.10.0

free(): invalid pointer

c++ code:

#include"pybind11/embed.h"
#include<iostream>
#include<thread>
#include<chrono>
#include<sstream>namespacepy= pybind11;
usingnamespacestd::chrono_literals;classWrapper
{
public:Wrapper()
{
py::gil_scoped_acquire acquire;
_obj = py::module::import("wrapper").attr("Wrapper")();
_wrapperInit = _obj.attr("wrapperInit");
_wrapperFini = _obj.attr("wrapperFini");
}
~Wrapper()
{
_wrapperInit.release();
_wrapperFini.release();
}
intwrapperInit()
{
py::gil_scoped_acquire acquire;
return_wrapperInit(nullptr).cast<int>();
}
voidwrapperFini(int x)
{
py::gil_scoped_acquire acquire;
_wrapperFini(x);
}
private:
py::object _obj;
py::object _wrapperInit;
py::object _wrapperFini;
};
voidthread_func(int iteration)
{
Wrapper w;
for (int i = 0; i < 1; i++)
{
w.wrapperInit();
std::stringstream msg;
msg << "iteration: " << iteration << " thread: " << std::this_thread::get_id() << std::endl;
std::cout << msg.str();
std::this_thread::sleep_for(100ms);
}
}
intmain() {
py::scoped_interpreter guard{};
py::gil_scoped_release release; // add this to release the GIL
std::vector<std::thread> threads;
for (int i = 0; i < 1; ++i)
threads.push_back(std::thread(thread_func, 1));
for (auto& t : threads)
t.join();
return0;
}

wrapper.py code is

classWrapper():
serviceId="mmocr"version="backup.0"''' 服务初始化 @param config: 插件初始化需要的一些配置,字典类型 key: 配置名 value: 配置的值 @return ret: 错误码。无错误时返回0 '''defwrapperInit(cls, config: {}) ->int:
importtorchprint(config)
print("Initializing ..")
return0defwrapperFini(cls) ->int:
return0

we run this code in ubuntu18.04 docker container. and the repo is public.ecr.aws/iflytek-open/opensource/demo/mmocr:v3.1

Reproducible example code

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew bug, unverified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions