[newlib-cygwin/cygwin-acl] Fix memory leak in pthread_getattr_np

Corinna Vinschen corinna@sourceware.org
Thu Oct 22 15:39:00 GMT 2015


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c173cb0805b81b20a4b2c5efe271e2f3f9ac61fb

commit c173cb0805b81b20a4b2c5efe271e2f3f9ac61fb
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Oct 21 12:46:32 2015 +0200

    Fix memory leak in pthread_getattr_np
    
    	* thread.cc (pthread_getattr_np): Fix memory leak, remove usage of
    	malloc for small local buffer.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/ChangeLog     | 5 +++++
 winsup/cygwin/release/2.3.0 | 2 ++
 winsup/cygwin/thread.cc     | 8 +++-----
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index b883cb4..41a02ef 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,10 @@
 2015-10-21  Corinna Vinschen  <corinna@vinschen.de>
 
+	* thread.cc (pthread_getattr_np): Fix memory leak, remove usage of
+	malloc for small local buffer.
+
+2015-10-21  Corinna Vinschen  <corinna@vinschen.de>
+
 	* path.cc (symlink_info::check_reparse_point): Don't generate an EIO
 	error if NtFsControlFile returns STATUS_NOT_A_REPARSE_POINT.
 
diff --git a/winsup/cygwin/release/2.3.0 b/winsup/cygwin/release/2.3.0
index ad34671..ad5cfd0 100644
--- a/winsup/cygwin/release/2.3.0
+++ b/winsup/cygwin/release/2.3.0
@@ -42,3 +42,5 @@ Bug Fixes
 
 - Fix EIO error accessing certain (OS X SMB?) drives
   Addresses: https://cygwin.com/ml/cygwin/2015-09/msg00229.html
+
+- Fix memory leak in calls to pthread_getattr_np.
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index b92a806..d9b6211 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -2485,8 +2485,7 @@ pthread::resume (pthread_t *thread)
 extern "C" int
 pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
 {
-  const size_t sizeof_tbi = sizeof (THREAD_BASIC_INFORMATION);
-  PTHREAD_BASIC_INFORMATION tbi;
+  THREAD_BASIC_INFORMATION tbi;
   NTSTATUS status;
 
   if (!pthread::is_good_object (&thread))
@@ -2506,13 +2505,12 @@ pthread_getattr_np (pthread_t thread, pthread_attr_t *attr)
   (*attr)->schedparam = thread->attr.schedparam;
   (*attr)->guardsize = thread->attr.guardsize;
 
-  tbi = (PTHREAD_BASIC_INFORMATION) malloc (sizeof_tbi);
   status = NtQueryInformationThread (thread->win32_obj_id,
 				     ThreadBasicInformation,
-				     tbi, sizeof_tbi, NULL);
+				     &tbi, sizeof (tbi), NULL);
   if (NT_SUCCESS (status))
     {
-      PTEB teb = (PTEB) tbi->TebBaseAddress;
+      PTEB teb = (PTEB) tbi.TebBaseAddress;
       /* stackaddr holds the uppermost stack address.  See the comments
 	 in pthread_attr_setstack and pthread_attr_setstackaddr for a
 	 description. */



More information about the Cygwin-cvs mailing list