gsoap调用webservice出现内存泄漏,该怎么解决
1个回答
2014-12-30 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464973
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
gsoap调用webservice出现内存泄漏
程序运行起来后内存一直增长,出现了内存泄漏,经过各模块的测试分析,将泄漏代码出现在这一段。
/*webservice客户端函数,上传本地数据库数据到远程服务器*/
int SendToWebService(char **data_values,int n_columns,sqlite3* conn)
{
char sql[200]=" ";
char *err_msg;
int res;
struct soap *clientSoap = soap_new();
SOAP_CMAC _ns1__SendOneMessage sendMsg;
SOAP_CMAC _ns1__SendOneMessageResponse sendMsgResponse;
#if 1
soap_init(clientSoap);
sendMsg.grpID=atoi(data_values[0]);
sendMsg.cTime=atoi(data_values[1]);
sendMsg.allEnCount=atoi(data_values[2]);
sendMsg.allOutCount=atoi(data_values[3]);
printf("sendMsg.grpID=%d;sendMsg.cTime=%d;sendMsg.enCount=%d;sendMsg.outCount=%d\n",sendMsg.grpID,sendMsg.cTime,sendMsg.allEnCount,sendMsg.allOutCount);
sprintf_s(buffer,sizeof(buffer),"sendMsg.grpID=%d;sendMsg.cTime=%d;sendMsg.enCount=%d;sendMsg.outCount=%d",sendMsg.grpID,sendMsg.cTime,sendMsg.allEnCount,sendMsg.allOutCount);
WriteLog(buffer);
struct SOAP_ENV__Header header;
clientSoap->header=&header;
string strid("admin");
string strpsw("123456");
SOAP_CMAC ns1__MySoapHeader mySoapHeader;
mySoapHeader.UserId=&strid;
mySoapHeader.UserPW=&strpsw;
header.ns1__MySoapHeader_=&mySoapHeader;
clientSoap->header=&header;
if(soap_call___ns1__SendOneMessage(clientSoap, NULL, NULL, &sendMsg, &sendMsgResponse)==SOAP_OK)
{
//printf("response=%d\n ", sendMsgResponse.SendOneMessageResult);
sprintf_s(buffer,sizeof(buffer),"sendMsgResponse.SendOneMessageResult=%d",sendMsgResponse.SendOneMessageResult);
WriteLog(buffer);
/*
-1 =验证失败, -2=失败,1=插入成功,2=更新成功;
插入成功,更新成功写数据库,将数据标为已发送。
失败,返回-1,上传数据线程释放资源
*/
switch(sendMsgResponse.SendOneMessageResult)
{
case 0:
soap_destroy(clientSoap);
soap_end(clientSoap);
soap_done(clientSoap);
return -1;
break;
case 1:
WriteLog("上传到服务器,数据插入成功");
sprintf_s(sql,sizeof(sql),"Update Grp set IsSend=%d where CTime=%d and GropId=%d",1,atoi(data_values[1]),atoi(data_values[0]));
res=sqlite3_exec(conn, sql, NULL, 0, &err_msg);
if(res!=SQLITE_OK)
{
fprintf(stderr,"操作失败,错误代码:%s",err_msg);
sprintf_s(buffer,sizeof(buffer),"操作失败,错误代码:%s",err_msg);
WriteLog(buffer);
}
else
{
printf("本地数据Issend更新为1成功\n");
WriteLog("本地数据Issend更新为1成功");
}
sqlite3_free(err_msg);
break;
case 2:
WriteLog("上传到服务器,数据更新成功");
sprintf_s(sql,sizeof(sql),"Update Grp set IsSend=%d where CTime=%d and GropId=%d",1,atoi(data_values[1]),atoi(data_values[0]));
res=sqlite3_exec(conn, sql, NULL, 0, &err_msg);
if(res!=SQLITE_OK)
{
fprintf(stderr,"操作失败,错误代码:%s\n",err_msg);
sprintf_s(buffer,sizeof(buffer),"操作失败,错误代码:%s",err_msg);
WriteLog(buffer);
}
else
{
printf("本地数据Issend更新为1成功\n");
WriteLog("本地数据Issend更新为1成功");
}
sqlite3_free(err_msg);
break;
case -1:
WriteLog("-1,连接服务器验证失败");
soap_destroy(clientSoap);
soap_end(clientSoap);
soap_done(clientSoap);
return -1;
break;
case -2:
WriteLog("-2,失败");
soap_destroy(clientSoap);
soap_end(clientSoap);
soap_done(clientSoap);
程序运行起来后内存一直增长,出现了内存泄漏,经过各模块的测试分析,将泄漏代码出现在这一段。
/*webservice客户端函数,上传本地数据库数据到远程服务器*/
int SendToWebService(char **data_values,int n_columns,sqlite3* conn)
{
char sql[200]=" ";
char *err_msg;
int res;
struct soap *clientSoap = soap_new();
SOAP_CMAC _ns1__SendOneMessage sendMsg;
SOAP_CMAC _ns1__SendOneMessageResponse sendMsgResponse;
#if 1
soap_init(clientSoap);
sendMsg.grpID=atoi(data_values[0]);
sendMsg.cTime=atoi(data_values[1]);
sendMsg.allEnCount=atoi(data_values[2]);
sendMsg.allOutCount=atoi(data_values[3]);
printf("sendMsg.grpID=%d;sendMsg.cTime=%d;sendMsg.enCount=%d;sendMsg.outCount=%d\n",sendMsg.grpID,sendMsg.cTime,sendMsg.allEnCount,sendMsg.allOutCount);
sprintf_s(buffer,sizeof(buffer),"sendMsg.grpID=%d;sendMsg.cTime=%d;sendMsg.enCount=%d;sendMsg.outCount=%d",sendMsg.grpID,sendMsg.cTime,sendMsg.allEnCount,sendMsg.allOutCount);
WriteLog(buffer);
struct SOAP_ENV__Header header;
clientSoap->header=&header;
string strid("admin");
string strpsw("123456");
SOAP_CMAC ns1__MySoapHeader mySoapHeader;
mySoapHeader.UserId=&strid;
mySoapHeader.UserPW=&strpsw;
header.ns1__MySoapHeader_=&mySoapHeader;
clientSoap->header=&header;
if(soap_call___ns1__SendOneMessage(clientSoap, NULL, NULL, &sendMsg, &sendMsgResponse)==SOAP_OK)
{
//printf("response=%d\n ", sendMsgResponse.SendOneMessageResult);
sprintf_s(buffer,sizeof(buffer),"sendMsgResponse.SendOneMessageResult=%d",sendMsgResponse.SendOneMessageResult);
WriteLog(buffer);
/*
-1 =验证失败, -2=失败,1=插入成功,2=更新成功;
插入成功,更新成功写数据库,将数据标为已发送。
失败,返回-1,上传数据线程释放资源
*/
switch(sendMsgResponse.SendOneMessageResult)
{
case 0:
soap_destroy(clientSoap);
soap_end(clientSoap);
soap_done(clientSoap);
return -1;
break;
case 1:
WriteLog("上传到服务器,数据插入成功");
sprintf_s(sql,sizeof(sql),"Update Grp set IsSend=%d where CTime=%d and GropId=%d",1,atoi(data_values[1]),atoi(data_values[0]));
res=sqlite3_exec(conn, sql, NULL, 0, &err_msg);
if(res!=SQLITE_OK)
{
fprintf(stderr,"操作失败,错误代码:%s",err_msg);
sprintf_s(buffer,sizeof(buffer),"操作失败,错误代码:%s",err_msg);
WriteLog(buffer);
}
else
{
printf("本地数据Issend更新为1成功\n");
WriteLog("本地数据Issend更新为1成功");
}
sqlite3_free(err_msg);
break;
case 2:
WriteLog("上传到服务器,数据更新成功");
sprintf_s(sql,sizeof(sql),"Update Grp set IsSend=%d where CTime=%d and GropId=%d",1,atoi(data_values[1]),atoi(data_values[0]));
res=sqlite3_exec(conn, sql, NULL, 0, &err_msg);
if(res!=SQLITE_OK)
{
fprintf(stderr,"操作失败,错误代码:%s\n",err_msg);
sprintf_s(buffer,sizeof(buffer),"操作失败,错误代码:%s",err_msg);
WriteLog(buffer);
}
else
{
printf("本地数据Issend更新为1成功\n");
WriteLog("本地数据Issend更新为1成功");
}
sqlite3_free(err_msg);
break;
case -1:
WriteLog("-1,连接服务器验证失败");
soap_destroy(clientSoap);
soap_end(clientSoap);
soap_done(clientSoap);
return -1;
break;
case -2:
WriteLog("-2,失败");
soap_destroy(clientSoap);
soap_end(clientSoap);
soap_done(clientSoap);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询