diff --git a/ChangeLog b/ChangeLog index 375388c..3fb8cfb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -193,6 +193,27 @@ Version 1.8.0 Version 1.6.7 ******************************************************************************* +2010-03-21 Marcelo Jimenez + * SF Bug Tracker [ 2392166 ] ithread_detach not called for finished worker thread + Submitted: Ulrik ( ulsv_enea ) - 2008-12-05 08:24 + + Valgrind reports a memory leak due to that the function ithread_detach is + not called for finished worker threads in ThreadPool.c. + + ==21137== 2,176 bytes in 8 blocks are possibly lost in loss record 5 of 5 + ==21137== at 0x4C20F3F: calloc (vg_replace_malloc.c:279) + ==21137== by 0x4010F58: _dl_allocate_tls (in /lib/ld-2.6.1.so) + ==21137== by 0x544BA92: pthread_create@@GLIBC_2.2.5 (in + /lib/libpthread-2.6.1.so) + ==21137== by 0x5F94592: CreateWorker (ThreadPool.c:639) + ==21137== by 0x5F95079: ThreadPoolInit (ThreadPool.c:784) + + I'm using libupnp 1.6.6 + + For more info on pthread_detach, see: + http://gelorakan.wordpress.com/2007/11/26/pthead_create-valgrind-memory-lea + k-solved/ + 2010-03-21 Marcelo Jimenez * SF Bug Tracker [ 2392304 ] Memory leak in SSDP AdvertiseAndReply Submitted: Ulrik ( ulsv_enea ) - 2008-12-05 08:24 diff --git a/upnp/sample/tvcombo/linux/upnp_tv_combo_main.c b/upnp/sample/tvcombo/linux/upnp_tv_combo_main.c index ee832f6..59e6efc 100644 --- a/upnp/sample/tvcombo/linux/upnp_tv_combo_main.c +++ b/upnp/sample/tvcombo/linux/upnp_tv_combo_main.c @@ -1,33 +1,33 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ #include "sample_util.h" diff --git a/upnp/sample/tvcombo/upnp_tv_ctrlpt.c b/upnp/sample/tvcombo/upnp_tv_ctrlpt.c index a176af4..9ca4be4 100644 --- a/upnp/sample/tvcombo/upnp_tv_ctrlpt.c +++ b/upnp/sample/tvcombo/upnp_tv_ctrlpt.c @@ -1,33 +1,33 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ #include "upnp_tv_ctrlpt.h" @@ -1294,12 +1294,12 @@ TvCtrlPointVerifyTimeouts( int incr ) * None * ********************************************************************************/ -void * -TvCtrlPointTimerLoop( void *args ) +static int TvCtrlPointTimerLoopRun = 1; +void *TvCtrlPointTimerLoop(void *args) { int incr = 30; // how often to verify the timeouts, in seconds - while( 1 ) { + while (TvCtrlPointTimerLoopRun) { isleep( incr ); TvCtrlPointVerifyTimeouts( incr ); } @@ -1322,66 +1322,72 @@ TvCtrlPointTimerLoop( void *args ) * TV_SUCCESS if everything went well, else TV_ERROR * ********************************************************************************/ -int -TvCtrlPointStart( print_string printFunctionPtr, - state_update updateFunctionPtr ) +int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionPtr) { - ithread_t timer_thread; - int rc; - unsigned short port = 0; - char *ip_address = NULL; + ithread_t timer_thread; + int rc; + unsigned short port = 0; + char *ip_address = NULL; - SampleUtil_Initialize( printFunctionPtr ); - SampleUtil_RegisterUpdateFunction( updateFunctionPtr ); + SampleUtil_Initialize(printFunctionPtr); + SampleUtil_RegisterUpdateFunction(updateFunctionPtr); - ithread_mutex_init( &DeviceListMutex, 0 ); + ithread_mutex_init(&DeviceListMutex, 0); - SampleUtil_Print( - "Initializing UPnP Sdk with\n" - "\tipaddress = %s port = %u\n", - ip_address, port ); + SampleUtil_Print( + "Initializing UPnP Sdk with\n" + "\tipaddress = %s port = %u\n", + ip_address, port); - rc = UpnpInit( ip_address, port ); - if( UPNP_E_SUCCESS != rc ) { - SampleUtil_Print( "WinCEStart: UpnpInit() Error: %d", rc ); - //UpnpFinish(); - //return TV_ERROR; - } + rc = UpnpInit(ip_address, port); + if (rc != UPNP_E_SUCCESS) { + SampleUtil_Print("WinCEStart: UpnpInit() Error: %d", rc); + /* + UpnpFinish(); + return TV_ERROR; + */ + } + if (!ip_address) { + ip_address = UpnpGetServerIpAddress(); + } + if (!port) { + port = UpnpGetServerPort(); + } - ip_address = UpnpGetServerIpAddress(); - port = UpnpGetServerPort(); + SampleUtil_Print( + "UPnP Initialized\n" + "\tipaddress= %s port = %u\n", + ip_address, port); - SampleUtil_Print( - "UPnP Initialized\n" - "\tipaddress= %s port = %u\n", - ip_address, port ); + SampleUtil_Print("Registering Control Point"); + rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler, + &ctrlpt_handle, &ctrlpt_handle); + if (rc != UPNP_E_SUCCESS) { + SampleUtil_Print( "Error registering CP: %d", rc ); + UpnpFinish(); - SampleUtil_Print( "Registering Control Point" ); - rc = UpnpRegisterClient( TvCtrlPointCallbackEventHandler, - &ctrlpt_handle, &ctrlpt_handle ); - if( UPNP_E_SUCCESS != rc ) { - SampleUtil_Print( "Error registering CP: %d", rc ); - UpnpFinish(); - return TV_ERROR; - } + return TV_ERROR; + } - SampleUtil_Print( "Control Point Registered" ); + SampleUtil_Print("Control Point Registered"); - TvCtrlPointRefresh(); + TvCtrlPointRefresh(); - // start a timer thread - ithread_create( &timer_thread, NULL, TvCtrlPointTimerLoop, NULL ); + /* start a timer thread */ + ithread_create(&timer_thread, NULL, TvCtrlPointTimerLoop, NULL); + ithread_detach(timer_thread); - return TV_SUCCESS; + return TV_SUCCESS; } -int -TvCtrlPointStop() +int TvCtrlPointStop(void) { - TvCtrlPointRemoveAll(); - UpnpUnRegisterClient( ctrlpt_handle ); - UpnpFinish(); - SampleUtil_Finish(); + TvCtrlPointTimerLoopRun = 0; + TvCtrlPointRemoveAll(); + UpnpUnRegisterClient( ctrlpt_handle ); + UpnpFinish(); + SampleUtil_Finish(); - return TV_SUCCESS; + return TV_SUCCESS; } + diff --git a/upnp/sample/tvctrlpt/linux/upnp_tv_ctrlpt_main.c b/upnp/sample/tvctrlpt/linux/upnp_tv_ctrlpt_main.c index d3d6f75..bd54b68 100644 --- a/upnp/sample/tvctrlpt/linux/upnp_tv_ctrlpt_main.c +++ b/upnp/sample/tvctrlpt/linux/upnp_tv_ctrlpt_main.c @@ -401,9 +401,7 @@ TvCtrlPointProcessCommand( char *cmdline ) return TV_SUCCESS; } -int -main( int argc, - char **argv ) +int main( int argc, char **argv ) { int rc; ithread_t cmdloop_thread; @@ -414,6 +412,7 @@ main( int argc, #endif int code; + rc = TvCtrlPointStart( linux_print, NULL ); if( rc != TV_SUCCESS ) { SampleUtil_Print( "Error starting UPnP TV Control Point" ); @@ -436,6 +435,7 @@ main( int argc, #endif rc = TvCtrlPointStop(); + return rc; } diff --git a/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c b/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c index 84ab52c..fdc915f 100644 --- a/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c +++ b/upnp/sample/tvctrlpt/upnp_tv_ctrlpt.c @@ -1299,12 +1299,12 @@ TvCtrlPointVerifyTimeouts( int incr ) * None * ********************************************************************************/ -void * -TvCtrlPointTimerLoop( void *args ) +static int TvCtrlPointTimerLoopRun = 1; +void *TvCtrlPointTimerLoop(void *args) { int incr = 30; // how often to verify the timeouts, in seconds - while( 1 ) { + while (TvCtrlPointTimerLoopRun) { isleep( incr ); TvCtrlPointVerifyTimeouts( incr ); } @@ -1327,66 +1327,70 @@ TvCtrlPointTimerLoop( void *args ) * TV_SUCCESS if everything went well, else TV_ERROR * ********************************************************************************/ -int -TvCtrlPointStart( print_string printFunctionPtr, - state_update updateFunctionPtr ) +int TvCtrlPointStart(print_string printFunctionPtr, state_update updateFunctionPtr) { - ithread_t timer_thread; - int rc; - unsigned short port = 0; - char *ip_address = NULL; + ithread_t timer_thread; + int rc; + unsigned short port = 0; + char *ip_address = NULL; - SampleUtil_Initialize( printFunctionPtr ); - SampleUtil_RegisterUpdateFunction( updateFunctionPtr ); + SampleUtil_Initialize(printFunctionPtr); + SampleUtil_RegisterUpdateFunction(updateFunctionPtr); - ithread_mutex_init( &DeviceListMutex, 0 ); + ithread_mutex_init(&DeviceListMutex, 0); - SampleUtil_Print( - "Initializing UPnP Sdk with\n" - "\tipaddress = %s port = %u\n", - ip_address, port ); + SampleUtil_Print( + "Initializing UPnP Sdk with\n" + "\tipaddress = %s port = %u\n", + ip_address, port); - rc = UpnpInit( ip_address, port ); - if( UPNP_E_SUCCESS != rc ) { - SampleUtil_Print( "WinCEStart: UpnpInit() Error: %d", rc ); - UpnpFinish(); - return TV_ERROR; - } + rc = UpnpInit(ip_address, port); + if (rc != UPNP_E_SUCCESS) { + SampleUtil_Print("WinCEStart: UpnpInit() Error: %d", rc); + UpnpFinish(); + return TV_ERROR; + } + if (!ip_address) { + ip_address = UpnpGetServerIpAddress(); + } + if (!port) { + port = UpnpGetServerPort(); + } - ip_address = UpnpGetServerIpAddress(); - port = UpnpGetServerPort(); + SampleUtil_Print( + "UPnP Initialized\n" + "\tipaddress= %s port = %u\n", + ip_address, port); - SampleUtil_Print( - "UPnP Initialized\n" - "\tipaddress= %s port = %u\n", - ip_address, port ); + SampleUtil_Print("Registering Control Point"); + rc = UpnpRegisterClient(TvCtrlPointCallbackEventHandler, + &ctrlpt_handle, &ctrlpt_handle); + if (rc != UPNP_E_SUCCESS) { + SampleUtil_Print( "Error registering CP: %d", rc ); + UpnpFinish(); - SampleUtil_Print( "Registering Control Point" ); - rc = UpnpRegisterClient( TvCtrlPointCallbackEventHandler, - &ctrlpt_handle, &ctrlpt_handle ); - if( UPNP_E_SUCCESS != rc ) { - SampleUtil_Print( "Error registering CP: %d", rc ); - UpnpFinish(); - return TV_ERROR; - } + return TV_ERROR; + } - SampleUtil_Print( "Control Point Registered" ); + SampleUtil_Print("Control Point Registered"); - TvCtrlPointRefresh(); + TvCtrlPointRefresh(); - // start a timer thread - ithread_create( &timer_thread, NULL, TvCtrlPointTimerLoop, NULL ); + /* start a timer thread */ + ithread_create(&timer_thread, NULL, TvCtrlPointTimerLoop, NULL); + ithread_detach(timer_thread); - return TV_SUCCESS; + return TV_SUCCESS; } -int -TvCtrlPointStop() +int TvCtrlPointStop(void) { - TvCtrlPointRemoveAll(); - UpnpUnRegisterClient( ctrlpt_handle ); - UpnpFinish(); - SampleUtil_Finish(); + TvCtrlPointTimerLoopRun = 0; + TvCtrlPointRemoveAll(); + UpnpUnRegisterClient( ctrlpt_handle ); + UpnpFinish(); + SampleUtil_Finish(); - return TV_SUCCESS; + return TV_SUCCESS; } + diff --git a/upnp/sample/tvdevice/linux/upnp_tv_device_main.c b/upnp/sample/tvdevice/linux/upnp_tv_device_main.c index 8eec536..f3c47b5 100644 --- a/upnp/sample/tvdevice/linux/upnp_tv_device_main.c +++ b/upnp/sample/tvdevice/linux/upnp_tv_device_main.c @@ -1,4 +1,4 @@ -/************************************************************************** +/******************************************************************************* * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. @@ -27,7 +27,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - **************************************************************************/ + ******************************************************************************/ #include "sample_util.h"