Click here to Skip to main content
15,919,028 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Button Code "DEFPUSHBUTTON" code not receving control Pin
ForNow27-Jan-09 2:47
ForNow27-Jan-09 2:47 
GeneralRe: Button Code "DEFPUSHBUTTON" code not receving control Pin
JudyL_MD27-Jan-09 3:35
JudyL_MD27-Jan-09 3:35 
GeneralRe: Button Code "DEFPUSHBUTTON" code not receving control Pin
ForNow27-Jan-09 6:04
ForNow27-Jan-09 6:04 
GeneralRe: Button Code "DEFPUSHBUTTON" code not receving control Pin
Mark Salsbery27-Jan-09 6:15
Mark Salsbery27-Jan-09 6:15 
GeneralRe: Button Code "DEFPUSHBUTTON" code not receving control Pin
ForNow27-Jan-09 6:40
ForNow27-Jan-09 6:40 
GeneralRe: Button Code "DEFPUSHBUTTON" code not receving control Pin
Mark Salsbery27-Jan-09 6:52
Mark Salsbery27-Jan-09 6:52 
GeneralRe: Button Code "DEFPUSHBUTTON" code not receving control Pin
ForNow27-Jan-09 13:13
ForNow27-Jan-09 13:13 
Questionheap corruption after call to select() [modified] Pin
aliusam26-Jan-09 13:59
aliusam26-Jan-09 13:59 
hi all
i am writing a thread per client server, well its not really a server, but it destributes jobs and calculations to other connected PCs.
i have been having this error

Free Heap block 00DB3D28 modified at 00DB3D78 after it was freed
Windows has triggered a breakpoint

now i traced the corruption of the heap by using _heapchk() and i found that the heap is being corrupted after a call to select() with fd_set containing one socket to check it for readability, the call to _heapchk() befor the select() returns _HEAPOK and after the select() it returns _HEAPBADNODE.
the call to select() is inside the client specific thread, the first client that connects has no problem at all, when a second client connects the select() works fine untill there are nothing to read from the socket, call select() and returns zero then the heap corrupts, how to solve such a problem where the code is not under my control???? i am using VC++ 2005 and win xp.
another thing, the thread proc is part of an object, that is creating a thread by calling a static function passing pointer to an object and inside the static function call a member function of object, dose that effect the heap in any way harmful??? i used to do it all the time with no problems.
here is the thread code:

thread(void* pParam)
{
	int bytesSent,bytesToBeSent;
	int bytesRecv = SOCKET_ERROR;
	char sendbuf[4096] = "";
	char recvbuf[4096] = "";
	char tempbuf[4096] = "";

	// tell client to send its status
	short* aa = (short*) &sendbuf[0];
	*aa = PGA_CMD_SENDSTATE;
	bytesToBeSent = 2;
	bytesSent = send( socket, sendbuf, bytesToBeSent, 0 );
	aa=NULL;

	NotCritical = true;

	/////// loop
	int cmd,i,j,s,ret = 0;
	TIMEVAL t;
	t.tv_sec=0;
	t.tv_usec=5000;
	fd_set fd;


	while( 1 )
	{
		FD_ZERO(&fd);
		FD_SET(socket,&fd);

		int hs2 = _heapchk();      // hs2 = _HEAPOK

		ret = select(0, &fd, NULL, NULL, &t);

		hs2 = _heapchk();         // hs2 = _HEAPBADNODE

		if ( ret > 0 )
		{
			s=0;
			bytesRecv = recv( socket, recvbuf, 4096, 0);
			if(bytesRecv == SOCKET_ERROR)
				goto ERR;
			cmd = *(short*)recvbuf;
			j=2;
			switch(cmd)
			{
			//////////here we process recv data
			}// end switch(cmd)

		}
		else	// if ( ret > 0 )
		{
			if( ret < 0)
				goto ERR;
		}


	}
ERR:
	closesocket(socket);
	state |= CI_STATE_ERROR;
	isBad = true;
	return 0;
}


any ideas??????

if i comment out the line
// ret = select(0, &amp;fd, NULL, NULL, &amp;t);


i can connect as many clients i want with no problem, but the thread will not read any thing from the socket since ret is always zero.

Ali Usam AlCherchefchi

modified on Monday, January 26, 2009 8:06 PM

AnswerRe: heap corruption after call to select() Pin
Cosmic Egg29-Jan-09 9:43
Cosmic Egg29-Jan-09 9:43 
QuestionHaving trouble with IOleCommandTarget interface Pin
Haim Nachum26-Jan-09 10:09
Haim Nachum26-Jan-09 10:09 
AnswerRe: Having trouble with IOleCommandTarget interface Pin
«_Superman_»26-Jan-09 17:32
professional«_Superman_»26-Jan-09 17:32 
GeneralRe: Having trouble with IOleCommandTarget interface Pin
Haim Nachum27-Jan-09 2:26
Haim Nachum27-Jan-09 2:26 
QuestionVC++ 2008 Application and MSI Package Pin
pratap198026-Jan-09 6:39
pratap198026-Jan-09 6:39 
AnswerRe: VC++ 2008 Application and MSI Package Pin
Stuart Dootson26-Jan-09 7:06
professionalStuart Dootson26-Jan-09 7:06 
GeneralRe: VC++ 2008 Application and MSI Package Pin
pratap198026-Jan-09 7:28
pratap198026-Jan-09 7:28 
AnswerRe: VC++ 2008 Application and MSI Package Pin
Randor 26-Jan-09 8:02
professional Randor 26-Jan-09 8:02 
GeneralRe: VC++ 2008 Application and MSI Package Pin
pratap198026-Jan-09 11:04
pratap198026-Jan-09 11:04 
QuestionHide some lines of RichEditCtrl Pin
SutterA25-Jan-09 22:17
SutterA25-Jan-09 22:17 
AnswerRe: Hide some lines of RichEditCtrl Pin
Stuart Dootson26-Jan-09 0:13
professionalStuart Dootson26-Jan-09 0:13 
AnswerRe: Hide some lines of RichEditCtrl Pin
Code-o-mat26-Jan-09 1:03
Code-o-mat26-Jan-09 1:03 
GeneralRe: Hide some lines of RichEditCtrl Pin
SutterA26-Jan-09 2:11
SutterA26-Jan-09 2:11 
Newstext object models Pin
SutterA28-Jan-09 1:57
SutterA28-Jan-09 1:57 
GeneralRe: text object models Pin
Code-o-mat28-Jan-09 2:23
Code-o-mat28-Jan-09 2:23 
GeneralRe: text object models Pin
SutterA2-Feb-09 1:58
SutterA2-Feb-09 1:58 
GeneralRe: text object models Pin
Code-o-mat2-Feb-09 2:04
Code-o-mat2-Feb-09 2:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.