You are here:

C/crash in _endthreadex

Advertisement


Question
Application is developed using the Visual Studio 6.0, use Multithreaded version of C Run Time Library, OS is Windows XP.
packet_handler_thrd is the function passed to _beingthreadex function while creating a thread in my application. Sometimes while terminating the thread i.e. in _endthreadex application crash. Every time application crash with the following crash stack:

0137ff54 00409118 003e1e90 0000003f 009b00e0 dhcpd32!__sbh_free_block+0xd2
0137ff64 0040cd2e 009b00e0 009b00e0 0040976c dhcpd32!free+0x43
0137ff7c 00409710 ffffffff 009a1f18 00000000 dhcpd32!calloc+0x3
0137ffb4 7c80b50b 009b00e0 00000000 00000000 dhcpd32!_beginthreadex+0xf0
0137ffec 00000000 004096ab 009b00e0 00000000 kernel32!BaseThreadStart+0x37

Thread Function is following:
int packet_handler_thrd(void *adhandle)
{
int i;
int res;
struct pcap_pkthdr *header;
u_char *pkt_data;

/* Read the packets coming on the ethernet interface */
while((res = pcap_next_ex( adhandle, &header,    &pkt_data)) >= 0)
{
packet_handler(adhandle,header,pkt_data);
}

if(res == -1)
{
 _endthreadex(0);
}
return 0;
}
Can u explain why it is behaving that way and is there any workaround to that?
Regards,
Arvind.

Answer
first of all I don't work on windows.
And by just looking at a piece of code, you will never be able to tell why the crash is happening/

When I look at the crash dump, I see that it is crashing at __sbh_free_block+0xd2.
So, you have to find out what value is getting passed to this function and what is the instruction at 0xd2.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.