From: Corinna Vinschen Date: Wed, 21 Oct 2015 10:46:32 +0000 (+0200) Subject: Fix memory leak in pthread_getattr_np X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=c173cb0805b81b20a4b2c5efe271e2f3f9ac61fb;p=newlib-cygwin.git 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 --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b883cb40a..41a02efe9 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2015-10-21 Corinna Vinschen + + * thread.cc (pthread_getattr_np): Fix memory leak, remove usage of + malloc for small local buffer. + 2015-10-21 Corinna Vinschen * path.cc (symlink_info::check_reparse_point): Don't generate an EIO diff --git a/winsup/cygwin/release/2.3.0 b/winsup/cygwin/release/2.3.0 index ad34671ad..ad5cfd001 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 b92a80620..d9b62111f 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. */