From 40505e9a58142ad7c51c2278e84b035c71102863 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sun, 5 Mar 2017 10:03:44 +0100 Subject: [PATCH] diff, prevent zombie proc + leak --- src/ce_diff.pas | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/ce_diff.pas b/src/ce_diff.pas index a96c112c..72329f63 100644 --- a/src/ce_diff.pas +++ b/src/ce_diff.pas @@ -35,30 +35,37 @@ begin inherited create(nil); p := TProcess.Create(self); - p.Executable:= 'diff' + exeExt; + try + p.Executable:= 'diff' + exeExt; - lbl.Caption:= 'The file: "' + fname2 + '" has been modified by another program.' - + LineEnding + 'Use the following diff to decide if the content should be ' - + 'reloaded.'; + lbl.Caption:= 'The file: "' + fname2 + '" has been modified by another program.' + + LineEnding + 'Use the following diff to decide if the content should be ' + + 'reloaded.'; - if exeInSysPath(p.Executable) then - begin - p.Parameters.Add('-u'); - p.Parameters.Add(fname1); - p.Parameters.Add(fname2); - p.Options:= [poUsePipes]; - p.ShowWindow:= swoHIDE; - p.Execute; + if exeInSysPath(p.Executable) then + begin + p.Parameters.Add('-u'); + p.Parameters.Add(fname1); + p.Parameters.Add(fname2); + p.Options:= [poUsePipes]; + p.ShowWindow:= swoHIDE; + p.Execute; - r := TStringList.Create; - try - processOutputToStrings(p,r); - editor.Lines.Assign(r); - finally - r.Free; - end; + r := TStringList.Create; + try + processOutputToStrings(p,r); + editor.Lines.Assign(r); + finally + r.Free; + end; + + while p.Running do + sleep(1); + end + else editor.Lines.Add('(The "diff" tool cannot be found)'); + finally + p.Free; end - else editor.Lines.Add('(The "diff" tool cannot be found)'); end; end.