-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Valgrind: bytes in 1 blocks are definitely lost #1646
Comments
I do not know the content of |
I can't provide full source code because it involves other modules. Some part is below. class Session {
public:
static void new_session(uint64_t session_id);
static void del_session(uint64_t session_id);
explicit Session(uint64_t id); // not used directly; not private due to std::piecewise_construct
Session() = delete;
void set_auth_state(const json &data);
void set_conn_state(const json &data);
private:
static std::mutex sessions_sync;
static std::unordered_map<uint64_t, Session> sessions;
uint64_t id;
json auth_state;
json conn_state;
};
}
void Session::new_session(uint64_t session_id) {
std::lock_guard<std::mutex> sessions_lock(sessions_sync);
if (sessions.find(session_id) == sessions.end()) {
sessions.emplace(std::piecewise_construct,
std::forward_as_tuple(session_id),
std::forward_as_tuple(session_id));
}
}
void Session::del_session(uint64_t session_id) {
std::lock_guard<std::mutex> sessions_lock(sessions_sync);
if (sessions.find(session_id) == sessions.end()) {
return;
}
sessions.erase(session_id);
}
Session::Session(uint64_t id)
: id(id)
{}
void Session::set_auth_state(const json &data) {
auth_state = data;
}
void Session::set_conn_state(const json &data) {
conn_state = data;
} It's guaranteed |
This is very odd. The library's objects do not share any state, so accessing two different values in two different threads is safe. The library further uses RAII for all memory allocations, so exceptions or anything should not yield a memory leak. Could you try to compile your application with ASAN or ThreadSanitizer and see if you get more diagnostics? |
Thank you for good suggestion! I'll try it for sure and post more details as I get them. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hello. I've caught a strange memory leak which happens not often. I reproduced it with v3.6.1 single_include json.hpp.
I use Object's private field
json auth_state
andsession.cpp:109
have just the instruction:No memory leaks with other variables, but Valgrind reports 2 records which are related with
nlohmann::json
:There is the same report about
json conn_state
variable. I've truncated some part which is related to the application. The application is multithreaded. But much more strange is the following report, which I was not truncated at all:I don't except that memory leak in my application. But I'd like you to have a look at nlohmann::json part as well. Now I temporary replaced the type of
auth_state
andconn_state
tostd::string
and haven't caught something the same.The text was updated successfully, but these errors were encountered: