多运行几次就会出现
malloc: *** error for object 0x1e206e14: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
以下是程序的调用顺序
NSString *u = [testURL stringByAppendingString:@"/time/set/getfamily"];
NSURL *url = [NSURL URLWithString:u];
NSDictionary *connectParams = [NSDictionary dictionaryWithObjectsAndKeys:
// [NSString stringWithFormat:@"%@", BINDID], @"bind_id",
BINDID, @"bind_id",
nil];
NSMutableData *_mdata = [self createJsonCompressAndEncrypt:connectParams];
NSData *reqdata = [WebService request:url body:_mdata];
NSDictionary *resultsDictionary = [NSDictionary dictionary];
if (reqdata.length == 0) {
//连接错误,服务器无返回
} else {
resultsDictionary = [self decryptDecompressJson:reqdata];
DLog(@"data --> dictionary: %@", resultsDictionary);
if (resultsDictionary && [resultsDictionary[@"ret"] intValue] == 0) {
ProtectSettingReturnMessage *userInfoReturnMessage = [[[ProtectSettingReturnMessage alloc] init] autorelease];
userInfoReturnMessage.cmdType = [NSString stringWithFormat:@"%@", resultsDictionary[@"mode"]];
userInfoReturnMessage.timeLength = [NSString stringWithFormat:@"%@", resultsDictionary[@"time_total"]];
userInfoReturnMessage.urlPeriod = resultsDictionary[@"time_period"];
userInfoReturnMessage.unlimited = [NSString stringWithFormat:@"%@", resultsDictionary[@"enabled"]];
return userInfoReturnMessage;
}
}
return nil;
NSString *requestJson = [reqParams JSONString];
DLog(@"reqParams: %@", [reqParams JSONString]);
//构造Json,格式为:XXX{}
NSString *inStr = [NSString stringWithFormat:@"%d", (int)++ requestNum];
NSString *requestStr = [inStr stringByAppendingString:requestJson];
// NSData *requestData = [requestStr dataUsingEncoding:[NSString defaultCStringEncoding]];
NSData *requestData = [requestStr dataUsingEncoding:NSUTF8StringEncoding];
//压缩,加密
// NSData *compressData = [NSData dataByCompressingData:requestData];
zlibCompress *zz = [[[zlibCompress alloc] init] autorelease];
NSData *compressData = [zz dataByCompressingData:requestData];
NSMutableData *_mdata = [[NSMutableData alloc] init];
if (compressData) {
NSData *desData = [Utility desData:compressData key:DESKey CCOperation:kCCEncrypt];
// NSString *desStr = [[NSString alloc] initWithData:desData encoding:[NSString defaultCStringEncoding]];
if (desData) {
_mdata = [NSMutableData dataWithData:desData];
} else {
DLog(@"请求数据加密失败!!!!");
}
} else {
DLog(@"请求数据压缩失败!!!!");
}
return _mdata;
Byte* bytes = (Byte*)[data bytes];
NSInteger len = [data length];
NSMutableData *compressedData = [[[NSMutableData alloc] initWithCapacity:len] autorelease];
Byte* compressedBytes = new Byte[len];
z_stream stream;
int err;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, @"deflateInit");
stream.next_in = bytes;
stream.avail_in = len;
stream.avail_out = 0;
while (stream.avail_out == 0) {
stream.avail_in = len - stream.total_in;
stream.next_out = compressedBytes;
stream.avail_out = COMPRESSION_BLOCK;
err = deflate(&stream, Z_NO_FLUSH);
[compressedData appendBytes:compressedBytes length:(stream.total_out-[compressedData length])];
if (err == Z_STREAM_END)
continue;
CHECK_ERR(err, @"deflate");
}
stream.avail_out = 0;
while (stream.avail_out == 0) {
stream.avail_in = len - stream.total_in;
stream.next_out = compressedBytes;
stream.avail_out = COMPRESSION_BLOCK;
err = deflate(&stream, Z_FINISH);
[compressedData retain];
[compressedData appendBytes:compressedBytes length:(stream.total_out-[compressedData length])];
if (err == Z_STREAM_END)
continue;
CHECK_ERR(err, @"deflate");
}
err = deflateEnd(&stream);
CHECK_ERR(err, @"deflateEnd");
delete[] compressedBytes;
return compressedData;
求大牛解解