Comments (9)
This is definitely not quite right - getting access violations sometimes
from uvw.
It's impossible to tell what you're doing wrong without a repro. As far as I can see, you can have tons of UBs everywhere. 🤷♂️
That being said, uvw
stays true to the requirements of libuv
and the latter requires users to close handles before leaving.
from uvw.
I apologize...here's a complete example:
#include <uvw.hpp>
#include <crtdbg.h>
#include <iostream>
auto setup_leak_detection() -> void;
auto main() -> int {
setup_leak_detection();
// Simple loop
auto loop = uvw::loop::get_default();
auto socket = loop->resource<uvw::pipe_handle>();
loop->walk([](auto&& h) {
h.close();
});
}
auto alloc_hook(
int /*allocType*/,
void* /*userData*/,
size_t size,
int /*blockType*/,
long request_number,
unsigned char const* /*filename*/,
int /*lineNumber*/) -> int {
// a memory leak can jump around a bit run to run
// so we define a window around the reported allocation
// number
int nominal_request = 163;
int leak_size = 200;
int const window_size = 20;
if (
request_number >= nominal_request - window_size &&
request_number <= nominal_request + window_size && size == leak_size)
{
// set a breakpoint here to find the allocation
int five = 5;
}
return true;
}
auto setup_leak_detection() -> void {
auto initial_flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
_CrtSetDbgFlag(initial_flag | _CRTDBG_LEAK_CHECK_DF);
_CrtSetAllocHook(alloc_hook);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
}
and here's the output:
Detected memory leaks!
Dumping objects ->
{168} normal block at 0x0000019C8710C6C0, 1192 bytes long.
Data: <h > 68 DD 97 C5 F7 7F 00 00 01 00 00 00 02 00 00 00
{167} normal block at 0x0000019C870F91B0, 24 bytes long.
Data: <8 > 38 DD 97 C5 F7 7F 00 00 01 00 00 00 02 00 00 00
{166} normal block at 0x0000019C870E6560, 120 bytes long.
Data: <0 > 30 DC 97 C5 F7 7F 00 00 CD CD CD CD CD CD CD CD
{165} normal block at 0x0000019C870E3740, 64 bytes long.
Data: < > 80 17 9C C5 F7 7F 00 00 00 00 00 00 00 00 00 00
{164} normal block at 0x0000019C870FE130, 16 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 CD CD CD CD
{163} normal block at 0x0000019C87104390, 200 bytes long.
Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.
from uvw.
ok...this seems to work:
auto main() -> int {
setup_leak_detection();
// Simple loop
auto loop = uvw::loop::get_default();
auto socket = loop->resource<uvw::pipe_handle>();
loop->walk([](auto&& h) {
h.close();
});
loop->run();
}
from uvw.
That's because you run the loop for another tick after closing your handles.
If you don't do that, handles aren't cleaned up properly and thus the leak.
It boils down to libuv
and how it works though. uvw
stays true to this requirement as mentioned. 👍
from uvw.
Sure - I get you probably don't want to reproduce the libuv docs, but I would suggest you update your "Code Example" to:
int main() {
auto loop = uvw::loop::get_default();
listen(*loop);
conn(*loop);
loop->run();
loop->walk([](auto&& h) {
h.close();
});
loop->run();
}
Since it seems that's the canonical approach people should use...but it's your library :)
from uvw.
Which code example? Do you mean this one?
from uvw.
yes - although optionally to your tests as well (libuv tests do something similar).
from uvw.
The test in the README file already closes handles as requested. I don't think there is nothing to fix.
Thanks for the heads-up though. I'm glad you found (and fixed) the issue. 👍
from uvw.
Related Issues (20)
- ErrorCode EPIPE -4047 Broken Pipe HOT 2
- Error in .vtu Files with hexahedron type of elements HOT 1
- loop::run not marked inline HOT 1
- 48 error HOT 1
- Vcpkg uvw version 2.12.1 HOT 1
- Is there 2.x backward compatibility layer? HOT 15
- uvw_fs_event and uvw_loop fail on Darwin PPC HOT 5
- create v2 branch for bug fixes HOT 4
- Provide a way to specify buffer size HOT 5
- How to Handle a Broken Pipe (SIGPIPE) in UVW? HOT 2
- Segmentation fault on calling thread.join due to destructor also calling thread.join HOT 5
- Q: cpp http server based on libuv HOT 3
- suppress compiler warning HOT 8
- Build issues HOT 5
- Error when building on Windows - multiple rules generate _deps/libuv-build/uv.lib HOT 4
- Issuing multiple filesystem operations at a time with user supplied buffer HOT 2
- Question: Pipe process output HOT 1
- uvw_net available HOT 8
- Run a task on next event loop iteration HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uvw.