From 88850aa7303634baf1d34730dcccbc8ac0e86d0f Mon Sep 17 00:00:00 2001 From: zhumos Date: Wed, 9 Aug 2023 14:57:32 +1000 Subject: [PATCH 1/2] Address FTP file descriptor leak as described in issue #2108 --- src/mavsdk/core/mavlink_ftp.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mavsdk/core/mavlink_ftp.cpp b/src/mavsdk/core/mavlink_ftp.cpp index 14ed043100..069c0e3981 100644 --- a/src/mavsdk/core/mavlink_ftp.cpp +++ b/src/mavsdk/core/mavlink_ftp.cpp @@ -1027,6 +1027,11 @@ MavlinkFtp::ServerResult MavlinkFtp::_work_list(PayloadHeader* payload, bool lis memcpy(&payload->data[offset], entry_s.c_str(), len); offset += len; } + + if (const int close_result = closedir(dfd); close_result != 0) { + LogWarn() << "FTP: Failed to close file descriptor (potential resource leak!). " + "Error code: " << close_result; + } } payload->size = offset; From ec11520a0224934a3a23b5cdd98099c8989967c7 Mon Sep 17 00:00:00 2001 From: zhumos Date: Sat, 12 Aug 2023 15:15:55 +1000 Subject: [PATCH 2/2] Fix style --- src/mavsdk/core/mavlink_ftp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mavsdk/core/mavlink_ftp.cpp b/src/mavsdk/core/mavlink_ftp.cpp index 069c0e3981..a4b268e4be 100644 --- a/src/mavsdk/core/mavlink_ftp.cpp +++ b/src/mavsdk/core/mavlink_ftp.cpp @@ -1030,7 +1030,8 @@ MavlinkFtp::ServerResult MavlinkFtp::_work_list(PayloadHeader* payload, bool lis if (const int close_result = closedir(dfd); close_result != 0) { LogWarn() << "FTP: Failed to close file descriptor (potential resource leak!). " - "Error code: " << close_result; + "Error code: " + << close_result; } }