未验证 提交 977550a1 编写于 作者: S slguan 提交者: GitHub

Merge pull request #421 from localvar/gzip-mem-leak

fix memory leak when request body is gziped
...@@ -321,10 +321,18 @@ bool httpReadDataImp(HttpContext *pContext) { ...@@ -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) { ...@@ -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) {
...@@ -367,7 +373,7 @@ bool httpReadData(HttpThread *pThread, HttpContext *pContext) { ...@@ -367,7 +373,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册