Fix memory leaks when when calling ThreadPoolAdd() or ThreadPoolAddPersistent()

Hi,

I had found some bugs about memory leak on libupnp-1.6.18.

It may lead to memory leak  when calling ThreadPoolAdd() or
ThreadPoolAddPersistent() which does not return 0.

See the attachment for patch.
(cherry picked from commit 8e3a71905b)

Conflicts:
	upnp/src/ssdp/ssdp_ctrlpt.c
This commit is contained in:
zexian chen 2013-09-10 17:27:07 -03:00 committed by Marcelo Roberto Jimenez
parent 490b0a5c86
commit c5777ae747
6 changed files with 45 additions and 12 deletions

View File

@ -357,6 +357,17 @@ Version 1.8.0
Version 1.6.19
*******************************************************************************
2013-09-10 zexian chen <chenzexian88(at)gmail.com>
Hi,
I had found some bugs about memory leak on libupnp-1.6.18.
It may lead to memory leak when calling ThreadPoolAdd() or
ThreadPoolAddPersistent() which does not return 0.
See the attachment for patch.
2013-09-03 Peng <howtofly(at)gmail.com>
Fix return value of config_description_doc.

1
THANKS
View File

@ -71,5 +71,6 @@ exempt of errors.
- Tom (tomdev2)
- Yoichi Nakayama (yoichi)
- zephyrus (zephyrus00jp)
- zexian chen
- Zheng Peng (darkelf2010)

View File

@ -96,10 +96,17 @@ static void *TimerThreadWorker(
/* If time has elapsed, schedule job. */
if (nextEvent && currentTime >= nextEventTime) {
if( nextEvent->persistent ) {
ThreadPoolAddPersistent( timer->tp, &nextEvent->job,
&tempId );
if (ThreadPoolAddPersistent( timer->tp, &nextEvent->job, &tempId ) != 0) {
if (nextEvent->job.arg != NULL && nextEvent->job.free_func != NULL) {
nextEvent->job.free_func(nextEvent->job.arg);
}
}
} else {
ThreadPoolAdd( timer->tp, &nextEvent->job, &tempId );
if (ThreadPoolAdd( timer->tp, &nextEvent->job, &tempId ) != 0) {
if (nextEvent->job.arg != NULL && nextEvent->job.free_func != NULL) {
nextEvent->job.free_func(nextEvent->job.arg);
}
}
}
ListDelNode( &timer->eventQ, head, 0 );
FreeTimerEvent( timer, nextEvent );

View File

@ -2013,7 +2013,9 @@ int UpnpSubscribeAsync(
TPJobInit(&job, (start_routine)UpnpThreadDistribution, Param);
TPJobSetFreeFunction(&job, (free_routine)free);
TPJobSetPriority(&job, MED_PRIORITY);
ThreadPoolAdd(&gSendThreadPool, &job, NULL);
if (ThreadPoolAdd(&gSendThreadPool, &job, NULL) != 0) {
free(Param);
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpSubscribeAsync\n");
@ -2199,7 +2201,9 @@ int UpnpUnSubscribeAsync(
TPJobInit( &job, ( start_routine ) UpnpThreadDistribution, Param );
TPJobSetFreeFunction( &job, ( free_routine ) free );
TPJobSetPriority( &job, MED_PRIORITY );
ThreadPoolAdd( &gSendThreadPool, &job, NULL );
if (ThreadPoolAdd( &gSendThreadPool, &job, NULL ) != 0) {
free(Param);
}
exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpUnSubscribeAsync\n");
@ -2325,7 +2329,9 @@ int UpnpRenewSubscriptionAsync(
TPJobInit( &job, ( start_routine ) UpnpThreadDistribution, Param );
TPJobSetFreeFunction( &job, ( free_routine ) free );
TPJobSetPriority( &job, MED_PRIORITY );
ThreadPoolAdd( &gSendThreadPool, &job, NULL );
if (ThreadPoolAdd( &gSendThreadPool, &job, NULL ) != 0) {
free(Param);
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpRenewSubscriptionAsync\n");
@ -2797,7 +2803,9 @@ int UpnpSendActionAsync(
TPJobSetFreeFunction( &job, ( free_routine ) free );
TPJobSetPriority( &job, MED_PRIORITY );
ThreadPoolAdd( &gSendThreadPool, &job, NULL );
if (ThreadPoolAdd( &gSendThreadPool, &job, NULL ) != 0) {
free(Param);
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpSendActionAsync \n");
@ -2917,7 +2925,9 @@ int UpnpSendActionExAsync(
TPJobSetFreeFunction( &job, ( free_routine ) free );
TPJobSetPriority( &job, MED_PRIORITY );
ThreadPoolAdd( &gSendThreadPool, &job, NULL );
if (ThreadPoolAdd( &gSendThreadPool, &job, NULL ) != 0) {
free(Param);
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpSendActionAsync\n");
@ -2984,7 +2994,9 @@ int UpnpGetServiceVarStatusAsync(
TPJobSetPriority( &job, MED_PRIORITY );
ThreadPoolAdd( &gSendThreadPool, &job, NULL );
if (ThreadPoolAdd( &gSendThreadPool, &job, NULL ) != 0) {
free(Param);
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpGetServiceVarStatusAsync\n");

View File

@ -910,6 +910,7 @@ int StartMiniServer(
sock_close(miniSocket->ssdpReqSock4);
sock_close(miniSocket->ssdpReqSock6);
#endif /* INCLUDE_CLIENT_APIS */
free(miniSocket);
return UPNP_E_OUTOF_MEMORY;
}
/* Wait for miniserver to start. */

View File

@ -295,9 +295,10 @@ void ssdp_handle_ctrlpt_msg(http_message_t *hmsg, struct sockaddr_storage *dest_
TPJobSetPriority(&job, MED_PRIORITY);
TPJobSetFreeFunction(&job,
(free_routine)
SSDPResultData_delete);
ThreadPoolAdd(&gRecvThreadPool, &job,
NULL);
free);
if (ThreadPoolAdd(&gRecvThreadPool, &job, NULL) != 0) {
SSDPResultData_delete(threadData);
}
}
}
node = ListNext(&ctrlpt_info->SsdpSearchList, node);