From 12c95723b77a871f704c6357fc1e1fdbacdcea6e Mon Sep 17 00:00:00 2001 From: crs Date: Wed, 27 Oct 2004 21:46:22 +0000 Subject: [PATCH] Fixed use of freed memory. --- lib/arch/CArchFileUnix.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/arch/CArchFileUnix.cpp b/lib/arch/CArchFileUnix.cpp index 4048061f..89bb51dc 100644 --- a/lib/arch/CArchFileUnix.cpp +++ b/lib/arch/CArchFileUnix.cpp @@ -52,6 +52,8 @@ CArchFileUnix::getBasename(const char* pathname) std::string CArchFileUnix::getUserDirectory() { + char* buffer = NULL; + std::string dir; #if HAVE_GETPWUID_R struct passwd pwent; struct passwd* pwentp; @@ -63,18 +65,16 @@ CArchFileUnix::getUserDirectory() #else long size = BUFSIZ; #endif - char* buffer = new char[size]; + buffer = new char[size]; getpwuid_r(getuid(), &pwent, buffer, size, &pwentp); - delete[] buffer; #else struct passwd* pwentp = getpwuid(getuid()); #endif if (pwentp != NULL && pwentp->pw_dir != NULL) { - return pwentp->pw_dir; - } - else { - return std::string(); + dir = pwentp->pw_dir; } + delete[] buffer; + return dir; } std::string