summaryrefslogtreecommitdiff
path: root/debian/patches/corefiles0001-trans-crash-fix-resource-leaks.patch
blob: f9c9d1ee7d60c883f7e1f4d7e1f46377ae4bb35a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
From 105d7bc17ff8ec01c27f3e9c3dca1468bde79b8d Mon Sep 17 00:00:00 2001
From: Justus Winter <justus@gnupg.org>
Date: Fri, 3 Jun 2016 16:55:55 +0200
Subject: [PATCH hurd 1/2] trans/crash: fix resource leaks

* trans/crash.c (S_crash_dump_task): Properly deallocate 'task',
'core_file', and 'ctty_id'.
---
 trans/crash.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/trans/crash.c b/trans/crash.c
index 5db9974..a541af7 100644
--- a/trans/crash.c
+++ b/trans/crash.c
@@ -217,7 +217,9 @@ S_crash_dump_task (mach_port_t port,
 	      proc_mark_stop (user_proc, signo, sigcode);
 
 	      c->task = task;
+	      task = MACH_PORT_NULL;
 	      c->core_file = core_file;
+	      core_file = MACH_PORT_NULL;
 	      c->core_limit = (off_t) -1; /* XXX should core limit in RPC */
 	      c->signo = signo;
 	      c->sigcode = sigcode;
@@ -251,17 +253,17 @@ S_crash_dump_task (mach_port_t port,
 	if (!err)
 	  err = proc_mark_exit (user_proc, W_EXITCODE (0, signo), sigcode);
 	err = task_terminate (task);
-	if (!err)
-	  {
-	    mach_port_deallocate (mach_task_self (), task);
-	    mach_port_deallocate (mach_task_self (), core_file);
-	    mach_port_deallocate (mach_task_self (), ctty_id);
-	  }
       }
     }
 
   if (user_proc != MACH_PORT_NULL)
     mach_port_deallocate (mach_task_self (), user_proc);
+  if (! err && MACH_PORT_VALID (task))
+    mach_port_deallocate (mach_task_self (), task);
+  if (! err && MACH_PORT_VALID (core_file))
+    mach_port_deallocate (mach_task_self (), core_file);
+  if (! err && MACH_PORT_VALID (ctty_id))
+    mach_port_deallocate (mach_task_self (), ctty_id);
 
   ports_port_deref (cred);
   return err;
-- 
2.1.4