From 625b92a94e9589adbb084040e54674902be1f3ab Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Wed, 4 May 2011 08:07:29 +0000
Subject: [PATCH] bug 1362: prevent leaking open file descriptors in case of
 cancellation

---
 RTCP/IONProc/src/BGL_Personality.cc | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/RTCP/IONProc/src/BGL_Personality.cc b/RTCP/IONProc/src/BGL_Personality.cc
index 4603c56d188..a59bf4d72ea 100644
--- a/RTCP/IONProc/src/BGL_Personality.cc
+++ b/RTCP/IONProc/src/BGL_Personality.cc
@@ -26,6 +26,7 @@
 #include <BGL_Personality.h>
 #include <Common/SystemCallException.h>
 #include <Thread/Mutex.h>
+#include <Thread/Cancellation.h>
 
 #include <cstdio>
 #include <cstdlib>
@@ -51,19 +52,18 @@ struct BGLPersonality *getBGLpersonality()
   if (!initialized) {
     initialized = true;
 
+    ScopedDelayCancellation dc; // don't leak open file descriptors
+
     int fd;
 
-    if ((fd = open("/proc/personality", O_RDONLY)) < 0) {
+    if ((fd = open("/proc/personality", O_RDONLY)) < 0)
       throw SystemCallException("open /proc/personality", errno, THROW_ARGS);
-    }
 
-    if (read(fd, &BGLPersonality, sizeof BGLPersonality) < 0) {
+    if (read(fd, &BGLPersonality, sizeof BGLPersonality) < 0)
       throw SystemCallException("read /proc/personality", errno, THROW_ARGS);
-    }
 
-    if (close(fd) < 0) {
+    if (close(fd) < 0)
       throw SystemCallException("close /proc/personality", errno, THROW_ARGS);
-    }
   }
 
   return &BGLPersonality;
-- 
GitLab