Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80edb96a authored by Ashish Kumar Gupta's avatar Ashish Kumar Gupta
Browse files

Fix memory leak in MtpFfsHandle.

The MtpFfsHandle class creates a number of child threads, but does not delete them when the handle is destroyed. This can lead to a memory leak. This CL fixes the memory leak by deleting the child threads when the handle is destroyed.

Bug: 365686062
Flag: EXEMPT bug fix
Test: Run mtp in host and device mode
Change-Id: I2fd586a01e3ff5bd49fbb53ba3a34a3f439049ae
parent 19d61365
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -298,9 +297,12 @@ int MtpFfsHandle::start(bool ptp) {

void MtpFfsHandle::close() {
    // Join all child threads before destruction
    for (auto& thread : mChildThreads) {
        thread.join();
    int count = mChildThreads.size();
    for (int i = 0; i < count; i++) {
        mChildThreads[i].join();
        delete &mChildThreads[i];
    }
    mChildThreads.clear();

    io_destroy(mCtx);
    closeEndpoints();