You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ab...@apache.org on 2020/05/29 17:55:43 UTC

[nifi-minifi-cpp] branch master updated: MINIFICPP-1243 - OsUtils::userIdToUsername leaks memory on Windows

This is an automated email from the ASF dual-hosted git repository.

aboda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d8f095  MINIFICPP-1243 - OsUtils::userIdToUsername leaks memory on Windows
8d8f095 is described below

commit 8d8f095119321676d5c38bbb8db2ed04c2315ed5
Author: Arpad Boda <ab...@apache.org>
AuthorDate: Fri May 29 16:59:17 2020 +0200

    MINIFICPP-1243 - OsUtils::userIdToUsername leaks memory on Windows
    
    Signed-off-by: Arpad Boda <ab...@apache.org>
    
    Approved by szaszm on GH
    
    This closes #801
---
 libminifi/src/utils/OsUtils.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libminifi/src/utils/OsUtils.cpp b/libminifi/src/utils/OsUtils.cpp
index 40652e1..f4a8e34 100644
--- a/libminifi/src/utils/OsUtils.cpp
+++ b/libminifi/src/utils/OsUtils.cpp
@@ -17,9 +17,12 @@
  */
 
 #include "utils/OsUtils.h"
+
 #include <iostream>
 #include <map>
 
+#include "utils/ScopeGuard.h"
+
 #ifdef WIN32
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
@@ -77,6 +80,7 @@ std::string OsUtils::userIdToUsername(const std::string &uid) {
     }
     // First call to LookupAccountSid to get the buffer sizes.
     PSID pSidOwner = NULL;
+    const utils::ScopeGuard guard_pSidOwner([&pSidOwner]() { if (pSidOwner != NULL) { LocalFree(pSidOwner); } });
     if (ConvertStringSidToSidA(name.c_str(), &pSidOwner)) {
       SID_NAME_USE sidType = SidTypeUnknown;
       DWORD windowsAccountNameSize = 0, dwwindowsDomainSize = 0;