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

[wiring] Thread: fixes memory leakage due to mutex not being destroyed. #2053

Merged
merged 1 commit into from Mar 22, 2020

Conversation

XuGuohui
Copy link
Member

Problem

Memory leakage if using wiring Mutex or RecursiveMutex class.

Solution

Add destructor which destroys the mutex if valid.

Example App

#include "Particle.h"

SYSTEM_MODE(MANUAL);
SerialLogHandler log(LOG_LEVEL_ALL);

void setup() {
}

void loop() {
    while(!Serial.isConnected());
    delay(1000);

    static runtime_info_t heapInfo;
    if (heapInfo.size == 0) {
        heapInfo.size = sizeof(heapInfo);
    }
    HAL_Core_Runtime_Info(&heapInfo, nullptr);
    Serial.printlnf("\n\n\n=======TP21============");
    Serial.printlnf("Heapinfo: size :%d, largest_free_block_heap :%lu", heapInfo.size, heapInfo.largest_free_block_heap);
    Serial.printlnf("===================\n\n\n");
    Mutex _buffer_mutex;
    HAL_Core_Runtime_Info(&heapInfo, nullptr);
    Serial.printlnf("\n\n\n=======TP22============");
    Serial.printlnf("Heapinfo: size :%d, largest_free_block_heap :%lu", heapInfo.size, heapInfo.largest_free_block_heap);
    Serial.printlnf("===================\n\n\n");
}

References

N/A


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

Copy link
Contributor

@eberseth eberseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

@XuGuohui XuGuohui added ready to merge PR has been reviewed and tested and removed needs review labels Mar 21, 2020
@XuGuohui XuGuohui merged commit 18e9c4e into develop Mar 22, 2020
@XuGuohui XuGuohui deleted the fix/wiring_mutex/ch49925 branch March 22, 2020 15:46
@avtolstoy avtolstoy added this to the 1.5.0 milestone Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ready to merge PR has been reviewed and tested
Projects
None yet
3 participants