From 9fe2e5a81b20902cd7dda588b95cd803447dee7e Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Fri, 27 Aug 1999 03:47:43 +0000 Subject: [PATCH] plugged a memory leak in GetCString(). --- xpcom/io/nsFileSpecMac.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xpcom/io/nsFileSpecMac.cpp b/xpcom/io/nsFileSpecMac.cpp index 0774c785021..c31fb5010a6 100644 --- a/xpcom/io/nsFileSpecMac.cpp +++ b/xpcom/io/nsFileSpecMac.cpp @@ -1131,10 +1131,13 @@ const char* nsFileSpec::GetCString() const { if (mPath.IsEmpty()) { - const_cast(this)->mPath - = MacFileHelpers::PathNameFromFSSpec(mSpec, true); - if (mPath.IsEmpty()) + char* path = MacFileHelpers::PathNameFromFSSpec(mSpec, true); + if (path != NULL) { + const_cast(this)->mPath = path; // operator =() copies the string!!! + delete[] path; + } else { const_cast(this)->mError = NS_ERROR_OUT_OF_MEMORY; + } } return mPath; }