问题描述
- linux下free(): invalid next size (fast)的问题
-
简单来说就是把mac地址转换成00:00:00:00:00:00这种形式,被调函数在for循环i=1时还很正常,i=2的时候执行到macValue += buffer这句话就挂了,报错 free(): invalid next size (fast),实在是找不到原因了,谷歌说内存泄露,可是我实在不知道string这里怎么泄露啊,求各位帮忙看看啊 不胜感激!(另外,我用小程序测试过这段代码完成没问题啊,可是放到大程序里面就不行了,嘤嘤嘤)
主调函数部分
rule.fieldValue[DL_SRC] = ::getMacValueAsString(ofm->match.dl_src);
被调用函数:
string getMacValueAsString(const uint8_t* macAddress)
{
string macValue ;
char buffer[8];for(int i = 0; i < OFP_ETH_ALEN; i++) { uint8_t upperNibble = macAddress[i] >> 4; uint8_t lowerNibble = macAddress[i] & (uint8_t)0xF; sprintf(buffer, "%x%x", upperNibble, lowerNibble); macValue += buffer; cout<<"macValue:"<<macValue<<endl; if(i != (OFP_ETH_ALEN - 1)) { macValue+=':'; } } return macValue;
}
时间: 2024-09-20 00:23:54