fix memory leak when request body is gziped
This commit is contained in:
parent
a9ad56780f
commit
2e0dc43636
|
@ -321,10 +321,18 @@ bool httpReadDataImp(HttpContext *pContext) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool httpUnCompressData(HttpContext *pContext) {
|
bool httpDecompressData(HttpContext *pContext) {
|
||||||
if (pContext->contentEncoding == HTTP_COMPRESS_GZIP) {
|
if (pContext->contentEncoding != HTTP_COMPRESS_GZIP) {
|
||||||
|
httpDump("context:%p, fd:%d, ip:%s, content:%s", pContext, pContext->fd, pContext->ipstr, pContext->parser.data.pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
char *decompressBuf = calloc(HTTP_DECOMPRESS_BUF_SIZE, 1);
|
char *decompressBuf = calloc(HTTP_DECOMPRESS_BUF_SIZE, 1);
|
||||||
int32_t decompressBufLen = pContext->parser.bufsize;
|
int32_t decompressBufLen = HTTP_DECOMPRESS_BUF_SIZE;
|
||||||
|
size_t bufsize = sizeof(pContext->parser.buffer) - (pContext->parser.data.pos - pContext->parser.buffer) - 1;
|
||||||
|
if (decompressBufLen > (int)bufsize) {
|
||||||
|
decompressBufLen = (int)bufsize;
|
||||||
|
}
|
||||||
|
|
||||||
int ret = httpGzipDeCompress(pContext->parser.data.pos, pContext->parser.data.len, decompressBuf, &decompressBufLen);
|
int ret = httpGzipDeCompress(pContext->parser.data.pos, pContext->parser.data.len, decompressBuf, &decompressBufLen);
|
||||||
|
|
||||||
|
@ -333,16 +341,14 @@ bool httpUnCompressData(HttpContext *pContext) {
|
||||||
pContext->parser.data.pos[decompressBufLen] = 0;
|
pContext->parser.data.pos[decompressBufLen] = 0;
|
||||||
httpDump("context:%p, fd:%d, ip:%s, rawSize:%d, decompressSize:%d, content:%s",
|
httpDump("context:%p, fd:%d, ip:%s, rawSize:%d, decompressSize:%d, content:%s",
|
||||||
pContext, pContext->fd, pContext->ipstr, pContext->parser.data.len, decompressBufLen, decompressBuf);
|
pContext, pContext->fd, pContext->ipstr, pContext->parser.data.len, decompressBufLen, decompressBuf);
|
||||||
|
pContext->parser.data.len = decompressBufLen;
|
||||||
} else {
|
} else {
|
||||||
httpError("context:%p, fd:%d, ip:%s, failed to decompress data, rawSize:%d, error:%d",
|
httpError("context:%p, fd:%d, ip:%s, failed to decompress data, rawSize:%d, error:%d",
|
||||||
pContext, pContext->fd, pContext->ipstr, pContext->parser.data.len, ret);
|
pContext, pContext->fd, pContext->ipstr, pContext->parser.data.len, ret);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
httpDump("context:%p, fd:%d, ip:%s, content:%s", pContext, pContext->fd, pContext->ipstr, pContext->parser.data.pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
free(decompressBuf);
|
||||||
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool httpReadData(HttpThread *pThread, HttpContext *pContext) {
|
bool httpReadData(HttpThread *pThread, HttpContext *pContext) {
|
||||||
|
@ -369,7 +375,7 @@ bool httpReadData(HttpThread *pThread, HttpContext *pContext) {
|
||||||
return false;
|
return false;
|
||||||
} else if (ret == HTTP_CHECK_BODY_SUCCESS){
|
} else if (ret == HTTP_CHECK_BODY_SUCCESS){
|
||||||
httpCleanUpContextTimer(pContext);
|
httpCleanUpContextTimer(pContext);
|
||||||
if (httpUnCompressData(pContext)) {
|
if (httpDecompressData(pContext)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
httpCloseContextByServer(pThread, pContext);
|
httpCloseContextByServer(pThread, pContext);
|
||||||
|
|
Loading…
Reference in New Issue