浏览代码

* Clean up mswindows/os2 ARGV release in InternalExit to avoid crash if called twice

git-svn-id: trunk@17702 -
pierre 14 年之前
父节点
当前提交
0af77f8957
共有 1 个文件被更改,包括 14 次插入4 次删除
  1. 14 4
      rtl/inc/system.inc

+ 14 - 4
rtl/inc/system.inc

@@ -896,10 +896,20 @@ Begin
 
 {$if defined(MSWINDOWS) or defined(OS2)}
   { finally release the heap if possible, especially
-    important for DLLs }
-  for i:=0 to argc do
-    sysfreemem(argv[i]);
-  sysfreemem(argv);
+    important for DLLs.
+    Reset the array to nil, and finally also argv itself to
+    avoid double freeing problem in case this function gets called twice. }
+  if assigned(argv) then
+    begin
+      for i:=0 to argc-1 do
+        if assigned(argv[i]) then
+          begin
+            sysfreemem(argv[i]);
+            argv[i]:=nil;
+          end;
+      sysfreemem(argv);
+      argv:=nil;
+    end;
 {$endif}
 {$ifdef LINUX}
   {sysfreemem already checks for nil}