Skip to content
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

Fix CI compiler warnings #9

Open
devenrao opened this issue Jan 16, 2020 · 1 comment
Open

Fix CI compiler warnings #9

devenrao opened this issue Jan 16, 2020 · 1 comment

Comments

@devenrao
Copy link
Contributor

There are some warning in CI build probably need to check and fix

home/jenkins-op/workspace/openbmc-repository-ci/openbmc/phosphor-certificate-manager/certificate.cpp:91: warning: the use of tempnam' is dangerous, better use mkstemp'

16:11:34 [certificate.hpp:88]: (performance) Function parameter 'filePath' should be passed by const reference.
16:11:34 [certs_manager.hpp:70]: (performance) Function parameter 'filePath' should be passed by const reference.
16:11:34 [certificate.cpp:212]: (performance) Function parameter 'filePath' should be passed by const reference.
16:11:34 [certs_manager.cpp:457]: (error) Memory pointed to by 'rsa' is freed twice.
16:11:34 [certificate.cpp:498]: (style) Consider using std::find_if algorithm instead of a raw loop.
16:11:34 [certs_manager.cpp:249]: (style) Statements following return, break, continue, goto or throw will never be executed.
16:11:34 [certs_manager.cpp:129]: (performance) Function parameter 'filePath' should be passed by const reference.
16:11:34 [certs_manager.cpp:216]: (performance) Function parameter 'alternativeNames' should be passed by const reference.
16:11:34 [certs_manager.cpp:216]: (performance) Function parameter 'challengePassword' should be passed by const reference.
16:11:34 [certs_manager.cpp:217]: (performance) Function parameter 'city' should be passed by const reference.
16:11:34 [certs_manager.cpp:217]: (performance) Function parameter 'commonName' should be passed by const reference.
16:11:34 [certs_manager.cpp:217]: (performance) Function parameter 'contactPerson' should be passed by const reference.
16:11:34 [certs_manager.cpp:218]: (performance) Function parameter 'country' should be passed by const reference.
16:11:34 [certs_manager.cpp:218]: (performance) Function parameter 'email' should be passed by const reference.
16:11:34 [certs_manager.cpp:218]: (performance) Function parameter 'givenName' should be passed by const reference.
16:11:34 [certs_manager.cpp:219]: (performance) Function parameter 'initials' should be passed by const reference.
16:11:34 [certs_manager.cpp:219]: (performance) Function parameter 'keyCurveId' should be passed by const reference.
16:11:34 [certs_manager.cpp:220]: (performance) Function parameter 'keyPairAlgorithm' should be passed by const reference.
16:11:34 [certs_manager.cpp:220]: (performance) Function parameter 'keyUsage' should be passed by const reference.
16:11:34 [certs_manager.cpp:221]: (performance) Function parameter 'organization' should be passed by const reference.
16:11:34 [certs_manager.cpp:221]: (performance) Function parameter 'organizationalUnit' should be passed by const reference.
16:11:34 [certs_manager.cpp:221]: (performance) Function parameter 'state' should be passed by const reference.
16:11:34 [certs_manager.cpp:222]: (performance) Function parameter 'surname' should be passed by const reference.
16:11:34 [certs_manager.cpp:222]: (performance) Function parameter 'unstructuredName' should be passed by const reference.
16:11:34 [certs_manager.cpp:309]: (performance) Function parameter 'challengePassword' should be passed by const reference.
16:11:34 [certs_manager.cpp:310]: (performance) Function parameter 'city' should be passed by const reference.
16:11:34 [certs_manager.cpp:310]: (performance) Function parameter 'commonName' should be passed by const reference.
16:11:34 [certs_manager.cpp:310]: (performance) Function parameter 'contactPerson' should be passed by const reference.
16:11:34 [certs_manager.cpp:311]: (performance) Function parameter 'country' should be passed by const reference.
16:11:34 [certs_manager.cpp:311]: (performance) Function parameter 'email' should be passed by const reference.
16:11:34 [certs_manager.cpp:311]: (performance) Function parameter 'givenName' should be passed by const reference.
16:11:34 [certs_manager.cpp:312]: (performance) Function parameter 'initials' should be passed by const reference.
16:11:34 [certs_manager.cpp:312]: (performance) Function parameter 'keyCurveId' should be passed by const reference.
16:11:34 [certs_manager.cpp:314]: (performance) Function parameter 'organization' should be passed by const reference.
16:11:34 [certs_manager.cpp:314]: (performance) Function parameter 'organizationalUnit' should be passed by const reference.
16:11:34 [certs_manager.cpp:314]: (performance) Function parameter 'state' should be passed by const reference.
16:11:34 [certs_manager.cpp:315]: (performance) Function parameter 'surname' should be passed by const reference.
16:11:34 [certs_manager.cpp:315]: (performance) Function parameter 'unstructuredName' should be passed by const reference.
16:11:34 [test/certs_manager_test.cpp:36]: (warning) Member variable 'TestCertificates::certId' is not initialized in the constructor.
16:11:34 [test/certs_manager_test.cpp:146]: (style) Class 'MainApp' has a constructor with 1 argument that is not explicit.
16:11:34

@matthewfischer
Copy link

These are all fixed with the exception of the first one:

home/jenkins-op/workspace/openbmc-repository-ci/openbmc/phosphor-certificate-manager/certificate.cpp:91: warning: the use of tempnam' is dangerous, better use mkstemp'

dkodihal pushed a commit to NVIDIA/phosphor-certificate-manager that referenced this issue May 7, 2024
```
Changes Added : Added event loop support in test code

problem : After adding support for sending events from phosphor-user-manager it is obsderved that it is calling sendEvent which internally calls async_send_handler and allocates memeory for context
since the event loop is not present in test code, callback is never called and
the CI was throwing memory leak error

Direct leak of 1 byte(s) in 1 object(s) allocated from:
    #0 0x7ffa787b91e7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
    openbmc#1 0x7ffa77ad6383 in operator() /usr/local/include/sdbusplus/asio/detail/async_send_handler.hpp:40
    openbmc#2 0x7ffa77ad6383 in async_send<sdbusplus::asio::connection::async_method_call_timed<phosphor::logging::sendEvent(phosphor::logging::MESSAGE_TYPE, sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level, const std::vector<std::__cxx11::basic_string<char> >&, const string&)::<lambda(boost::system::error_code)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >
    (phosphor::logging::sendEvent(phosphor::logging::MESSAGE_TYPE, sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level, const std::vector<std::__cxx11::basic_string<char> >&, const string&)::<lambda(boost::system::error_code)>&&, const string&, const string&, const string&, const string&, uint64_t, const std::__cxx11::basic_string<char>&, const std::__cxx11::basic_string<char>&, const std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >&)::<lambda(boost::system::error_code, sdbusplus::message_t&)> > /usr/local/include/sdbusplus/asio/connection.hpp:98
    openbmc#3 0x7ffa77ad6383 in async_method_call_timed<phosphor::logging::sendEvent(phosphor::logging::MESSAGE_TYPE, sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level, const std::vector<std::__cxx11::basic_string<char> >&, const string&)::<lambda(boost::system::error_code)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > /usr/local/include/sdbusplus/asio/connection.hpp:192
    openbmc#4 0x7ffa77ad6383 in async_method_call<phosphor::logging::sendEvent(phosphor::logging::MESSAGE_TYPE, sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level, const std::vector<std::__cxx11::basic_string<char> >&, const string&)::<lambda(boost::system::error_code)>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > /usr/local/include/sdbusplus/asio/connection.hpp:221
    openbmc#5 0x7ffa77ad6383 in phosphor::logging::sendEvent(phosphor::logging::MESSAGE_TYPE, sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../lib/redfish_event_log.cpp:112
    openbmc#6 0x55dfba9084a3 in phosphor::certs::Manager::replaceCertificate(phosphor::certs::Certificate*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../certs_manager.cpp:493
    openbmc#7 0x55dfba8ab09d in phosphor::certs::Certificate::replace(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) ../certificate.cpp:315
    openbmc#8 0x55dfba7981e0 in TestBody ../test/certs_manager_test.cpp:677
    openbmc#9 0x7ffa786e3f2e in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /googletest-662fe38e44900c007eccb65a5d2ea19df7bd520e/googletest/src/gtest.cc:2607
    openbmc#10 0x7ffa786e3f2e in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /googletest-662fe38e44900c007eccb65a5d2ea19df7bd520e/googletest/src/gtest.cc:2643

```

Solution : The memory leak error was thrown because the
memory allocated by "async_send_handler" in sdbusplus was not getting de-allocated
because the callback is never getting called called since there was no event loop
present in test code.

Added event loop support in test code

Fixes jira https://jirasw.nvidia.com/browse/DGXOPENBMC-8905
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

No branches or pull requests

2 participants