Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
CTCPClient* m_Client = new CTCPClient();
MTSOutputDebugString("Huawei-zte Switch SendCommand");
CTL1Response * reponse = new CTL1Response(m_Manager, "HU");
reponse->m_Tl1ParamsMap=this->m_Tl1Map;
strcpy(reponse->m_technologyid,"AXE");

strcpy(h.ip,msan.ip);
h.port = msan.port;

reponse->THip=h.ip;
reponse->THport=h.port;
//string switch_uname = "root";
//string switch_pwd = "root";


m_Client->Bind();
errorno = m_Client->Connect(h.ip,h.port);

if(errorno != 1)
{
MTSOutputDebugString("HUAWEI-zte MSAN Connection Failed");

reponse->CreateResponse(ResponseString,NO_AVAILABLE_TESTHEAD);

return ResponseString;
}
else
{

MTSOutputDebugString("HUAWEI-zte MSAN Connection sucess \n");
}

char * bbuf = new char [1000];
pots = "config\r\n";

m_Client->Write(username.c_str());
m_Client->Write("\r\n");
errorno = m_Client->Read(bbuf,300,12,":",1,&mread);

m_Client->Write((char*)pwd.c_str());
m_Client->Write("\r\n");
errorno = m_Client->Read(bbuf,800,6,"#",1,&mread);

MTSOutputDebugString((char*)bbuf);
m_Client->Write((char*)pots.c_str());
m_Client->Read(bbuf,200,5,":",1,&mread);
MTSOutputDebugString((char*)bbuf);
if(errorno<1)
{
m_Client->Disconnect();
delete m_Client;
return "HUAWEI-zte MSAN send pots failed ";
}
///////////////////////
m_Client->Write("ag\r\n");
errorno = m_Client->Read(bbuf,800,5,"#",1,&mread);
int * shelf;shelf = new int;
int * rac; rac = new int ;
int* slot;slot = new int ;
*shelf = 3;
* rac = 1;
* slot = 2;
////// not tested begin

int circit = terminalid;;
terminalid /= 32;

if(terminalid > 0)
{
//*slot = terminalid;
terminalid *= 32;
circit -=terminalid;
}
m_Manager->m_DB.zte_get(terminalid,(int &)*rac,(int &)*shelf,(int &)*slot);

sleep(5);
//////////
char * num = new char[4];
//int num1[4];
pots = "get-sunitinfo rack "+string(itoa(*rac,num,10))+" shelf "+string(itoa(*shelf,num,10))+" slot "+string(itoa(*slot,num,10))+"";
m_Client->Write(pots.c_str());
m_Client->Write("\r\n");
//sleep(5);
///////////////////////////*/
pots = "start item 29 times 1 obliged 0 unit "+ parsing(bbuf,-2)+" sunit "+parsing(bbuf,-3)+" index "+string(itoa(circit,num,10))+" \r\n" ; // get out voltage

delete []num;
delete shelf;delete slot;delete rac;

m_Client->Write("exit\r\n");
errorno = m_Client->Read(bbuf,800,3,"#",1,&mread);
m_Client->Write("112\r\n");
errorno = m_Client->Read(bbuf,100,3,"#",1,&mread);


m_Client->Write((char*)pots.c_str(),true);

errorno = m_Client->Read(bbuf,600,6,"RESULT",1,&mread);
sleep(7);
errorno = m_Client->Read(bbuf,1000,18,"#",sizeof(bbuf),&mread);

if(errorno<1)
{
delete []bbuf;
m_Client->Disconnect();
delete m_Client;
reponse->CreateResponse(ResponseString,NO_AVAILABLE_TESTHEAD);

}
if(strstr(bbuf,"User busy")!=NULL)
{
delete []bbuf;
m_Client->Disconnect();
delete m_Client;
reponse->CreateResponse(ResponseString,LINE_IS_BUSY);

return ResponseString;
}

pots = string(bbuf);
m_Client->Write("exit\r\n");
errorno = m_Client->Read(bbuf,100,5,"#",1,&mread);
m_Client->Write("logout\r\n");
m_Client->Disconnect();
delete []bbuf;//free(bbuf);
MTSOutputDebugString("\n test\n");
m_Manager->dbSection.Lock();
delete m_Client ;
m_Manager->dbSection.Unlock();
MTSOutputDebugString("\n test\n");

if(atoi(GetResultValue(pots,"Total failure count :").c_str())> 0 )
{
MTSOutputDebugString("\nFail\n");
delete []bbuf;
m_Client->Disconnect();
reponse->CreateResponse(ResponseString,NO_AVAILABLE_TESTHEAD);
delete m_Client;
delete reponse->m_GData;
delete reponse->m_db;
delete reponse->m_cs;
delete reponse;
// sleep(3);
return ResponseString;

}

//bool busy = true;
reponse->m_GData->dcvoldata.b_ae = true;
//,":");
reponse->m_GData->dcvoldata.sae = GetResultValue(pots,"A-GND DC Vol:");
/////////

//pots = "";
///////////////////////////////////////////////

//   sleep
Posted
Updated 16-May-14 2:41am
v2
Comments
KarstenK 15-May-14 13:18pm    
nobody will answer your question. Write better code by checking that your objects are valid and you not are oeverwriting memory or double delete an object.

write some debugging message to locate the error
Mahmoud_Gamal 15-May-14 13:25pm    
i cant due to it thread section from big multi threading question
but what should i do
Mahmoud_Gamal 15-May-14 13:33pm    
it is a
windows service the debuging data just some long address in memory <br>
 <br>
but can i optimize this function or divide it into two function
Sergey Alexandrovich Kryukov 15-May-14 17:45pm    
What is "violet"? This word is never mentioned in the post, except for the title.
—SA
Mahmoud_Gamal 16-May-14 8:44am    
thanks for hint i improve question :)

From the middle of your code:
C++
if(errorno<1)
{
delete []bbuf;
m_Client->Disconnect();
delete m_Client;
reponse->CreateResponse(ResponseString,NO_AVAILABLE_TESTHEAD);

}
if(strstr(bbuf,"User busy")!=NULL)
{
delete []bbuf;
m_Client->Disconnect();
delete m_Client;
reponse->CreateResponse(ResponseString,LINE_IS_BUSY);

return ResponseString;
}

The first if deletes bbuf, but then the second if accesses it again, leading to access exception. Also you delete m_Client in the first if block although you still access it later
 
Share this answer
 
Comments
Mahmoud_Gamal 16-May-14 12:58pm    
THANKS I WILL TRY IT REALLY I SEE CODE MORE TIME BUT I DIDN'T SEE IT I HOPE THIS TO BE THE PROBLEM THANKS VERY WELL :)
Don't use new/delete when you don't need them.

Replace these with simple int declarations ...

c++>int
int shelf = 3;
int rac = 1;
int slot = 2;


... and adjust references to these variables accordingly.

Replace:

C++
char * bbuf = new char [1000];


... with ...

C++
char pbuf[1000] = {0};


... and remove the delete[] pbuf statements.

Replace:

C++
char num = new char[4];


... with ...

C++
char num[4] = {0};


... and remove the delete[] num statements.

Also, looks like clause ...

C++
if(errorno<1)


... is missing a return statement ...

C++
return ResponseString;
 
Share this answer
 
Comments
Mahmoud_Gamal 18-May-14 5:05am    
this case cause stack overflow //if i do like this
Stefan_Lang 19-May-14 2:15am    
The subject line in your question implies you already do get a stack overflow - then why do you think these suggestions cause one? Have you resolved the first stack overflow? If so, how? What is the exact error message that you get?

You are not providing any useful information. Please remember that we don't see your full program or the messages on your screen, and you haven't even given us a full description of what your actual problem is!
Mahmoud_Gamal 19-May-14 3:49am    
yes as you say my brother :) but first the stack overflow occur in say as example on the
line 20 when i use memory pointer in these variable in may be case at line 50
or not due to this is peace of threading application
Stefan_Lang 19-May-14 4:12am    
If after performing the suggested changes a stack overflow happens at a different location, then the suggestions actually work in the sense that they fix the first stack overflow error.

That said, you still haven't provided us with any useful information of the errors that you get. Anyway, I do no think that you get an actual stack overflow: such an error usually only occurs in the case of endless recursion, or in rare cases of very limited stack size combined with deep function call stacks. Likely you're using the wrong word all the time, which doesn't help at all in helping you find the problem - all we can do is fish in the dark and point out obvious problems of your code that may or may not be related to the error you are facing!

Again: please post the actual error message! Literally! And completely!
Mahmoud_Gamal 19-May-14 5:32am    
i sorry i know, may be i use wrong words but this errors not occur constantly i want to prevent it permanently for that i optimize code
if you have windows multi threading code in c++ 6 and mutex aemaphore in one project
you will help me ////////////
this code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900