作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我测试了我使用 libuv 的小程序。
程序的调试输出显示内存泄漏。
libuv版本
#define UV_VERSION_MAJOR 0
#define UV_VERSION_MINOR 9
我的测试代码
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crtdbg.h>
#include <conio.h>
#include <uv.h>
void on_new_connection(uv_stream_t *server, int status) {
}
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
uv_tcp_t server;
uv_tcp_init(uv_default_loop(), &server);
struct sockaddr_in bind_addr = uv_ip4_addr("0.0.0.0", 9123);
uv_tcp_bind(&server, bind_addr);
// leak occurred here
uv_listen((uv_stream_t*)&server, 128, on_new_connection);
//uv_close((uv_handle_t*)&server, NULL);
return 0;
}
Detected memory leaks!
Dumping objects ->
{56} normal block at 0x002A3258, 11136 bytes long.
Data: <T B > 54 F8 42 00 09 00 00 00 CD CD CD CD CD CD CD CD
Object dump complete.
调用栈
uv_tcp_listen(...)
uv_listen(...)
main(...)
代码
uv_tcp_listen(...)
{
....
if(!handle->accept_reqs) {
handle->accept_reqs = (uv_tcp_accept_t*)
malloc(uv_simultaneous_server_accepts * sizeof(uv_tcp_accept_t)); <<
....
}
最佳答案
uv_listen() 确实调用了 malloc() 但这不是泄漏。但是,如果您关闭服务器句柄(并等待关闭回调),内存将再次被释放。
关于c++ - libuv 会导致 uv_listen() 内存泄漏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14546954/
我测试了我使用 libuv 的小程序。 程序的调试输出显示内存泄漏。 条件 libuv版本 #define UV_VERSION_MAJOR 0 #define UV_VERSION_MINOR 9
我是一名优秀的程序员,十分优秀!