![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| IP Networking Learn TCP/IP, Internet Protocol, Routing, Routers, Network protocols in this UNIX and Linux forum. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with memory leak | kshk123 | HP-UX | 2 | 05-25-2009 07:01 AM |
| memory leak problem | sonali | High Level Programming | 5 | 05-25-2009 06:55 AM |
| Memory leak in pthread | mindTeaser | UNIX for Advanced & Expert Users | 4 | 05-18-2009 01:30 AM |
| Memory leak of fork() | whererush | High Level Programming | 7 | 05-11-2006 11:51 AM |
| about virtual memory and memory leak | shriashishpatil | High Level Programming | 4 | 02-20-2006 11:31 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
memory leak?
Hi All,
my client server application can work in two modes: 1) one direction - only client sends msgs to server 2) two directions - server gives 'answers' to client. when program run in the first mode it looks OK, but when server answers to client than client's application exit its operation after a short while. I am trying to find the problem but have some taugh time. this is the function that reads the data in the client side (in which I have problems): Code:
int TCPClient::readSocketData(int s,
char *decodeUnifiedMsgForServer,
int n,
bool& isMsg
)
{
int bcount; int br;
bcount = 0;
br = 0;
while (bcount < n)
{
if ((br = recv(s,decodeUnifiedMsgForServer,n-bcount,0)) > 0)
{
isMsg = true;
bcount += br; decodeUnifiedMsgForServer+= br;
}
else if (br < 0) /* signal an error to the caller */
{
return(-1);
}
else {
return bcount;
}
//Y 17_04_05 -
Sleep(0);
//Y.
}
return(bcount);
}
Code:
void BrainControlComData::decodeMsg(char* decodeUnifiedMsgForServer)
{
if(strlen(decodeUnifiedMsgForServer) == 0)
{
char* error = "probably an error (see Q1 below)";
}
char* msg = decodeUnifiedMsgForServer;
int size = 4;
int lenCursorData;
int lenManipData;
int lenVzData;
//places 1 - 12 in msg are reserved for total size/ isEventMsg/ MsgID
int Web_lenOfClass;
// decode len of msg
memcpy(&Web_lenOfClass, msg, size);
int lenOfClass = ntohl(Web_lenOfClass);
int Web_MsgID;
// decode msg ID
memcpy(&Web_MsgID, msg + MSG_ID_LOCATION, size);
int msgID = ntohl(Web_MsgID);
//Y 6_07_05 -
int counter = 12;
int len = 0;
len = comData[CURSOR_DATA]->decodeMsg(msg + counter);
counter += len;
len = comData[STATE_DATA]->decodeMsg(msg);
}
my questions are as follows: 1) why is the length of the buffer (decodeUnifiedMsgForServer) is always 0 and not equals to the length of the msg received from server? I know that the data is received from the server because it is logged correctly, but still when I check length of msg it equas 0 (first 'if' in second function) - any ideas? 2) when I remarked the line that calls the decodeMsg the application 'behaved' OK and client didn't exit its operation. I think that this error has something to do with memory leak. maybe if I understood the first question I could understand this one as well. Thank you so much for your help, Lenna |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|