Przeglądaj źródła

* fix remaining search handle leaks in Dos.FSearch - fix for bug #30896

git-svn-id: trunk@34910 -
Tomas Hajny 8 lat temu
rodzic
commit
1e6ee7f3c7

+ 35 - 20
rtl/amicommon/dos.pp

@@ -804,27 +804,42 @@ var
 begin
   { No wildcards allowed in these things }
   if (pos('?',path)<>0) or (pos('*',path)<>0) or (path='') then
-    FSearch:=''
-  else begin
-    repeat
-      p1:=pos(';',dirlist);
-      if p1<>0 then begin
-        newdir:=Copy(dirlist,1,p1-1);
-        Delete(dirlist,1,p1);
-      end else begin
-        newdir:=dirlist;
-        dirlist:='';
-      end;
-      if (newdir<>'') and (not (newdir[length(newdir)] in ['/',':'])) then
-        newdir:=newdir+'/';
-      FindFirst(newdir+path,anyfile,tmpSR);
-      if doserror=0 then
-        newdir:=newdir+path
-      else
-        newdir:='';
-    until (dirlist='') or (newdir<>'');
-    FSearch:=newdir;
+  begin
+    FSearch:='';
+    exit;
+  end;
+  { check if the file specified exists }
+  findfirst(path,anyfile and not(directory), tmpSR);
+  if doserror=0 then
+  begin
+    findclose(tmpSR);
+    fsearch:=path;
+    exit;
   end;
+  findclose(tmpSR);
+
+  repeat
+    p1:=pos(';',dirlist);
+    if p1<>0 then 
+    begin
+      newdir:=Copy(dirlist,1,p1-1);
+      Delete(dirlist,1,p1);
+    end 
+    else 
+    begin
+      newdir:=dirlist;
+      dirlist:='';
+    end;
+    if (newdir<>'') and (not (newdir[length(newdir)] in [DirectorySeparator, DriveSeparator])) then 
+      newdir:=newdir+DirectorySeparator;
+    FindFirst(newdir+path,anyfile and not(directory),tmpSR);
+    if doserror=0 then
+      newdir:=newdir+path
+    else
+      newdir:='';
+    findclose(tmpSR);
+  until (dirlist='') or (newdir<>'');
+  FSearch:=newdir;
 end;
 
 

+ 1 - 0
rtl/go32v2/dos.pp

@@ -1001,6 +1001,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow slash as backslash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/msdos/dos.pp

@@ -783,6 +783,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow slash as backslash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/netware/dos.pp

@@ -370,6 +370,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow backslash as slash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/netwlibc/dos.pp

@@ -472,6 +472,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow backslash as slash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/os2/dos.pas

@@ -126,6 +126,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow slash as backslash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/watcom/dos.pp

@@ -649,6 +649,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow slash as backslash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/win/dos.pp

@@ -568,6 +568,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow slash as backslash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/win16/dos.pp

@@ -818,6 +818,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow slash as backslash }
   DoDirSeparators(dirlist);
  repeat

+ 1 - 0
rtl/wince/dos.pp

@@ -424,6 +424,7 @@ begin
      fsearch:=path;
      exit;
     end;
+  findclose(s);
   { allow slash as backslash }
   DoDirSeparators(dirlist);
  repeat