This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Fix memory leak in pthread_getattr_np


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

commit c0345822e502f45b412ab595e14c51dfdae5aaef
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 5d2675d..4cbbd0b 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 f2391a9..d6fda3b 100644
--- a/winsup/cygwin/release/2.3.0
+++ b/winsup/cygwin/release/2.3.0
@@ -39,3 +39,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. */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]