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
diff --git a/media/mtp/MtpFfsHandle.cpp b/media/mtp/MtpFfsHandle.cpp
index 979edab..4645a75 100644
--- a/media/mtp/MtpFfsHandle.cpp
+++ b/media/mtp/MtpFfsHandle.cpp
@@ -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 @@
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();