]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup fde data members before memset in fde::clean() corrupts their state.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 6 Sep 2008 05:15:20 +0000 (23:15 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sat, 6 Sep 2008 05:15:20 +0000 (23:15 -0600)
This prevents fde::timeoutHandler and fde::closeHandler memory leaks but there
will probably be more corruption as fde data members are added or changed.

Made fde::clean() private to prevent it from spreading through the code.
Use a new fde object to clean an old one, for now.

src/fd.cc
src/fde.h

index 9e190f42e2bdce0276cccee66c2c3d844055d280..d4931af13b1c996cc2a3fe74b2223653d29fef54 100644 (file)
--- a/src/fd.cc
+++ b/src/fd.cc
@@ -103,8 +103,7 @@ fd_close(int fd)
     F->flags.open = 0;
     fdUpdateBiggest(fd, 0);
     Number_FD--;
-    F->clear();
-    F->timeout = 0;
+    *F = fde();
 }
 
 #ifdef _SQUID_MSWIN_
index a4403af0adb2e80b0e8734637f033789cefef669..fd2302a8028d317e13430bb64bfe9a97eb86c50d 100644 (file)
--- a/src/fde.h
+++ b/src/fde.h
@@ -44,11 +44,6 @@ class fde
 
 public:
     fde() { clear(); };
-    /** Clear the fde class properly back to NULL equivalent. */
-    inline void clear() {
-        memset(this, 0, sizeof(fde));
-        local_addr.SetEmpty(); // IPAddress likes to be setup nicely.
-    }
     
     /**
      * Return true if the the comm_close for this fd called.
@@ -128,6 +123,16 @@ public:
     unsigned char upstreamTOS;                 /* see FwdState::dispatch()  */
 #endif
 
+private:
+    /** Clear the fde class back to NULL equivalent. */
+    inline void clear() {
+        timeoutHandler = NULL;
+        closeHandler = NULL;
+        // XXX: the following memset may corrupt or leak new or changed members
+        memset(this, 0, sizeof(fde));
+        local_addr.SetEmpty(); // IPAddress likes to be setup nicely.
+    }
+    
 };
 
 #endif /* SQUID_FDE_H */