Conversation
|
Could you please attach information about leaks? |
| size_t payload_size = data.size(); | ||
| Message* message = HandleIncomingMessage( | ||
| protocol_version, json_plus_binary_data, payload_size); | ||
| const auto message = std::shared_ptr<Message>(HandleIncomingMessage( |
There was a problem hiding this comment.
@SNiukalov Can't see any sharing here. What is teh reason to create shared_ptr?
| size_t full_data_size = data.size() + PROTOCOL_HEADER_V2_SIZE; | ||
| Message* message = | ||
| HandleIncomingMessage(protocol_version, data, payload_size); | ||
| const auto message = std::shared_ptr<Message>( |
There was a problem hiding this comment.
@SNiukalov Can't see any sharing here. What is teh reason to create shared_ptr?
| // Act | ||
| RawMessage* result_message = | ||
| MobileMessageHandler::HandleOutgoingMessageProtocol(message_to_send); | ||
| std::shared_ptr<RawMessage> result_message( |
There was a problem hiding this comment.
@SNiukalov Can't see any sharing here. What is the reason to create shared_ptr?
| // Act | ||
| RawMessage* result_message = | ||
| MobileMessageHandler::HandleOutgoingMessageProtocol(message_to_send); | ||
| std::shared_ptr<RawMessage> result_message( |
There was a problem hiding this comment.
@SNiukalov Can't see any sharing here. What is the reason to create shared_ptr?
| size_t full_size = | ||
| sizeof(uint8_t) * full_data.size() + bin_dat->size() * sizeof(uint8_t); | ||
|
|
||
| delete bin_dat; |
There was a problem hiding this comment.
@SNiukalov Why do you use heap? Is it possible to use stack for bin_dat? ?
|
|
||
| RawMessage* ptr = | ||
| MobileMessageHandler::HandleOutgoingMessageProtocol(message); | ||
| std::shared_ptr<RawMessage> ptr( |
There was a problem hiding this comment.
@SNiukalov Can't see any sharing here. What is the reason to create shared_ptr?
|
|
||
| ResumptionDataTest::~ResumptionDataTest() { | ||
| for (auto& submenu : test_submenu_map) { | ||
| delete submenu.second; |
There was a problem hiding this comment.
@SNiukalov why do we dlete only second item? Don't we clear the entire map?
| menu_title_ = new sm::SmartObject(sm_title); | ||
|
|
||
| if (menu_icon_) { | ||
| delete menu_icon_; |
There was a problem hiding this comment.
@SNiukalov Smart pointers for all such items?
There was a problem hiding this comment.
@AByzhynar
No, because this field we using int the ReturnPointee
| std::swap(delegates_queue_, empty_queue); | ||
| delegates_queue_lock_.Release(); | ||
| do { | ||
| auto delegate = empty_queue.front(); |
There was a problem hiding this comment.
@SNiukalov The name looks bad. How can we pop and delete something from an empty queue? ))
| std::make_shared<AsyncRunner>("test"); | ||
| async_runner->Stop(); | ||
| async_runner->AsyncRun(&mock_thread_delegate); | ||
| async_runner->AsyncRun(mock_thread_delegate); |
There was a problem hiding this comment.
@SNiukalov Is Async_runner responsible for thread delegate destruction?
There was a problem hiding this comment.
@AByzhynar
Yes, Async_runner responsible for thread delegate destruction
| /** | ||
| * @bref clearDelegateQueue delete leftover delegates in the queue | ||
| */ | ||
| void clearDelegateQueue(); |
There was a problem hiding this comment.
@SNiukalov Wrong naming(Coding style). The function name should start with a capital letter
| if (!delegates_queue_.empty()) { | ||
| std::queue<threads::ThreadDelegate*> queue_to_delete; | ||
| delegates_queue_lock_.Acquire(); | ||
| std::swap(delegates_queue_, queue_to_delete); |
There was a problem hiding this comment.
@SNiukalov No appropriate header files included
|
|
||
| void AsyncRunner::AsyncRunnerDelegate::clearDelegateQueue() { | ||
| if (!delegates_queue_.empty()) { | ||
| std::queue<threads::ThreadDelegate*> queue_to_delete; |
There was a problem hiding this comment.
@SNiukalov No appropriate header files included
There was a problem hiding this comment.
@AByzhynar
Header file for the std::queue present in async_runner.h
There was a problem hiding this comment.
@SNiukalov It does not matter. You define the entity here - so don't create implicit dependency from header file. Include all headers explicitly
There was a problem hiding this comment.
@AByzhynar
I don’t understand why we need duplicates.
This inclusion is present in the header file and also defines the entity.
If you change this header, we will still be forced to change the code in this place. Because it depends on the member of the delegates_queue_ class.
What is the meaning of this inclusion then?
There was a problem hiding this comment.
@SNiukalov You defining implicit dependency. This is BAD. You will change something in header e.g. change container from queue to list. What you get is CC file can't be compiled.
Read https://github.com/smartdevicelink/sdl_core/wiki/SDL-Coding-Style-Guide
Don't create dependencies between independent things.
There was a problem hiding this comment.
@AByzhynar
Yes, if change container from queue to list. What you get is CC file can't be compiled.
And if make include to cc I get is CC file can't be compiled. :) Because deffirents types :)
| { | ||
| call_with_param_count = 0; | ||
| char* ptr = new char; | ||
| char* ptr = const_cast<char*>("dealloc is not called"); |
There was a problem hiding this comment.
@SNiukalov Can you please explain this magic?
There was a problem hiding this comment.
@AByzhynar
In this case, we check that the CallFreeFunction will never be called and the memory will not be freed.
But we pass the pointer from the heap and make a memory leak.
I change this behavior and leave a reminder with text: dealloc not called


Fixes #Jira task
This PR is ready for review.
Risk
This PR makes no API changes.
Testing Plan
ATF scripts & Valgrind
Memory Leaks Report
after fix
after fix
after fix
after fix
Summary
Fix memory leaks in sdl and unit tests
CLA