Skip to content

fix cpp session mem leak#16443

Merged
HTHou merged 2 commits into
apache:masterfrom
hongzhi-gao:freatue/cpp-session-memleak
Sep 19, 2025
Merged

fix cpp session mem leak#16443
HTHou merged 2 commits into
apache:masterfrom
hongzhi-gao:freatue/cpp-session-memleak

Conversation

@hongzhi-gao

@hongzhi-gao hongzhi-gao commented Sep 19, 2025

Copy link
Copy Markdown
Contributor

Description

Content1

fix cpp sesssion builder memory leak


This PR has:

  • [√] been tested
        try {
            auto builder = std::make_shared<TableSessionBuilder>();
            auto session = std::shared_ptr<TableSession>(builder->username("root")
                    ->password("root")
                    ->nodeUrls(node_urls)
                    ->build());
            session->executeNonQueryStatement("show timeseries");
            session->close();
        }
        catch (const exception &e) {
            printf("exception: %s\n", e.what());
        }
$ valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./iotdbapp 
==95960== Memcheck, a memory error detector
==95960== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==95960== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==95960== Command: ./iotdbapp
==95960== 
Thrift: Fri Sep 19 10:37:16 2025 TSocket::open() timed out <Host: 127.0.0.1 Port: 6667>
[WARN]  /home/hongzhi/target/build/main/generated-sources-cpp/NodesSupplier.cpp:209 (fetchLatestEndpoints) - Failed to fetch endpoints from 127.0.0.1:6667 , error=open() timed out
[ERROR] /home/hongzhi/target/build/main/generated-sources-cpp/NodesSupplier.cpp:229 (refreshEndpointList) - NodesSupplier::refreshEndpointList failed: NodesSupplier::fetchLatestEndpoints failed: all nodes unreachable.
Thrift: Fri Sep 19 10:37:17 2025 TSocket::open() timed out <Host: 127.0.0.1 Port: 6667>
[WARN]  /home/hongzhi/target/build/main/generated-sources-cpp/NodesSupplier.cpp:209 (fetchLatestEndpoints) - Failed to fetch endpoints from 127.0.0.1:6667 , error=open() timed out
[ERROR] /home/hongzhi/target/build/main/generated-sources-cpp/NodesSupplier.cpp:229 (refreshEndpointList) - NodesSupplier::refreshEndpointList failed: NodesSupplier::fetchLatestEndpoints failed: all nodes unreachable.
Thrift: Fri Sep 19 10:37:19 2025 TSocket::open() timed out <Host: 127.0.0.1 Port: 6667>
[DEBUG] /home/hongzhi/target/build/main/generated-sources-cpp/SessionConnection.cpp:110 (init) - open() timed out
[DEBUG] /home/hongzhi/target/build/main/generated-sources-cpp/Session.cpp:795 (initDefaultSessionConnection) - open() timed out
[DEBUG] /home/hongzhi/target/build/main/generated-sources-cpp/Session.cpp:950 (open) - open() timed out
exception: open() timed out
==95960== 
==95960== HEAP SUMMARY:
==95960==     in use at exit: 0 bytes in 0 blocks
==95960==   total heap usage: 349 allocs, 349 frees, 106,622 bytes allocated
==95960== 
==95960== All heap blocks were freed -- no leaks are possible
==95960== 
==95960== For lists of detected and suppressed errors, rerun with: -s
==95960== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


Key changed/added classes (or packages if there are too many classes) in this PR

Modified SessionBuilder to use smart pointers.

@HTHou HTHou merged commit 9cbb773 into apache:master Sep 19, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants