[hurd,commited] hurd: optimize exec cleanup

Message ID 20220115232720.657859-1-samuel.thibault@ens-lyon.org
State Committed, archived
Headers
Series [hurd,commited] hurd: optimize exec cleanup |

Checks

Context Check Description
dj/TryBot-apply_patch fail Patch failed to apply to master at the time it was sent
dj/TryBot-32bit fail Patch series failed to apply

Commit Message

Samuel Thibault Jan. 15, 2022, 11:27 p.m. UTC
  When ports are nul we do not need to request their deallocation. It is
also useless to look for them in portnames.
---
 hurd/hurdexec.c               | 26 ++++++++++++++------------
 sysdeps/mach/hurd/dl-sysdep.c | 26 ++++++++++++++------------
 2 files changed, 28 insertions(+), 24 deletions(-)
  

Patch

diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index d5a20cb9b0..0545935d80 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -383,19 +383,21 @@  retry:
 	     exec call.  */
 
 	  for (i = 0; i < _hurd_nports; ++i)
-	    {
-	      *pdp++ = ports[i];
-	      for (j = 0; j < nportnames; j++)
-		if (portnames[j] == ports[i])
-		  portnames[j] = MACH_PORT_NULL;
-	    }
+	    if (ports[i] != MACH_PORT_NULL)
+	      {
+		*pdp++ = ports[i];
+		for (j = 0; j < nportnames; j++)
+		  if (portnames[j] == ports[i])
+		    portnames[j] = MACH_PORT_NULL;
+	      }
 	  for (i = 0; i < dtablesize; ++i)
-	    {
-	      *pdp++ = dtable[i];
-	      for (j = 0; j < nportnames; j++)
-		if (portnames[j] == dtable[i])
-		  portnames[j] = MACH_PORT_NULL;
-	    }
+	    if (dtable[i] != MACH_PORT_NULL)
+	      {
+		*pdp++ = dtable[i];
+		for (j = 0; j < nportnames; j++)
+		  if (portnames[j] == dtable[i])
+		    portnames[j] = MACH_PORT_NULL;
+	      }
 
 	  /* Pack ports to be destroyed together.  */
 	  for (i = 0, j = 0; i < nportnames; i++)
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 6d52558c24..3cbe075615 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -611,19 +611,21 @@  __rtld_execve (const char *file_name, char *const argv[],
     }
 
   for (i = 0; i < portarraysize; ++i)
-    {
-      *pdp++ = ports[i];
-      for (j = 0; j < nportnames; j++)
-	if (portnames[j] == ports[i])
-	  portnames[j] = MACH_PORT_NULL;
-    }
+    if (ports[i] != MACH_PORT_NULL)
+      {
+	*pdp++ = ports[i];
+	for (j = 0; j < nportnames; j++)
+	  if (portnames[j] == ports[i])
+	    portnames[j] = MACH_PORT_NULL;
+      }
   for (i = 0; i < dtablesize; ++i)
-    {
-      *pdp++ = dtable[i];
-      for (j = 0; j < nportnames; j++)
-	if (portnames[j] == dtable[i])
-	  portnames[j] = MACH_PORT_NULL;
-    }
+    if (dtable[i] != MACH_PORT_NULL)
+      {
+	*pdp++ = dtable[i];
+	for (j = 0; j < nportnames; j++)
+	  if (portnames[j] == dtable[i])
+	    portnames[j] = MACH_PORT_NULL;
+      }
 
   /* Pack ports to be destroyed together.  */
   for (i = 0, j = 0; i < nportnames; i++)