This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Fix resource leak in cygpath.cc


Mark Mitchell wrote:
> The cygpath utility calls FindFirstFile, but never calls FindClose.  As
> a result, in leaks search handles.  When you're using it for just one
> file, that's not a big deal, but if you feed it enough files, it gets
> unhappy.  Also, if you've got a long running cygpath in one window, you
> can't do file renames in named directories in another because cygpath
> still has the handles open.
> 
> Here's a patch.  I don't claim to have tested this in any comprehensive
> way, but I've played with it, and it fixes the problems I've been seeing.
> 
> Hope this helps,

Bleck!  My first posting on this list, and I rudely attached the wrong
file.  I'm very sorry.

Here's the right one.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
2007-03-30  Mark Mitchell  <mark@codesourcery.com>

	* utils/cygpath.cc (get_long_path_name_w32impl): Close handles
	returned by FindFirstFile.

--- /home/mitchell/Desktop/cygpath.cc	2007-03-30 15:26:57.339051200 -0700
+++ cygpath.cc	2007-03-30 14:16:39.474059200 -0700
@@ -375,8 +375,13 @@ get_long_path_name_w32impl (LPCSTR src, 
       ptr[len] = 0;
       if (next[1] != ':' && strcmp(next, ".") && strcmp(next, ".."))
 	{
-	  if (FindFirstFile (buf2, &w32_fd) != INVALID_HANDLE_VALUE)
+	  HANDLE h;
+	  h = FindFirstFile (buf2, &w32_fd);
+	  if (h != INVALID_HANDLE_VALUE)
+	    {
 	    strcpy (ptr, w32_fd.cFileName);
+	      FindClose (h);
+	    }
 	}
       ptr += strlen (ptr);
       if (pelem)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]