Memory leak fix in threadutil

Put thread in a detached state when calling pthread_create otherwise in
some circumstances, thread can end before the call to pthread_detach.
This commit is contained in:
Fabrice Fontaine 2012-04-02 15:44:44 +02:00
parent c154c63cdc
commit dc4eda529f
3 changed files with 33 additions and 1 deletions

View File

@ -2,6 +2,15 @@
Version 1.6.17
*******************************************************************************
2012-04-02 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
SF Bug Tracker id 3514145 - Memory leak fix in threadutil
Submitted: Fabrice Fontaine ( ffontaine ) - 2012-04-02 06:49:20 PDT
Put thread in a detached state when calling ithread_create otherwise in
some circumstances, thread can end before the call to ithread_detach.
2012-03-30 Fabrice Fontaine <fabrice.fontaine(at)orange.com>
Add --enable-unspecified_server

View File

@ -5,6 +5,7 @@
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
* Copyright (c) 2012 France Telecom All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -76,7 +77,8 @@ extern "C" {
#define ITHREAD_STACK_MIN PTHREAD_STACK_MIN
#define ITHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED
#define ITHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE
/***************************************************************************
* Name: ithread_t
@ -778,6 +780,22 @@ static UPNP_INLINE int ithread_cleanup_thread(void) {
***************************************************************************/
#define ithread_attr_setstacksize pthread_attr_setstacksize
/****************************************************************************
* Function: ithread_attr_setdetachstate
*
* Description:
* Sets detach state of a thread attribute object.
* Parameters:
* ithread_attr_t *attr (must be valid non NULL pointer to
* ithread_attr_t)
* int detachstate (value of detachstate must be ITHREAD_CREATE_DETACHED
* or ITHREAD_CREATE_JOINABLE)
* Returns:
* 0 on success. Nonzero on failure.
* See man page for pthread_attr_setdetachstate
***************************************************************************/
#define ithread_attr_setdetachstate pthread_attr_setdetachstate
/****************************************************************************
* Function: ithread_create
*

View File

@ -647,10 +647,15 @@ static int CreateWorker(
}
ithread_attr_init(&attr);
ithread_attr_setstacksize(&attr, tp->attr.stackSize);
ithread_attr_setdetachstate(&attr, ITHREAD_CREATE_DETACHED);
rc = ithread_create(&temp, &attr, WorkerThread, tp);
ithread_attr_destroy(&attr);
if (rc == 0) {
rc = ithread_detach(temp);
/* ithread_detach will return EINVAL if thread has been
successfully detached by ithread_create */
if (rc == EINVAL)
rc = 0;
tp->pendingWorkerThreadStart = 1;
/* wait until the new worker thread starts */
while (tp->pendingWorkerThreadStart) {