Memory leaks with valgrind on helloworld
nqle opened this issue · 2 comments
nqle commented
Hey, I tried using your library with nng 1.3.0 and ran
valgrind -v --leak-check=full --show-leak-kinds=all helloWorld
to check for any memory issues.
Several memory leaks are reported and I wondered if you also have this issue.
cwzx commented
The "leaks" you're seeing are produced by nng and are expected.
nng internally maintains global state that persists for the lifetime of the process.
nng does provide a function to free all state nng_fini()
. Calling this at the very end of the program will result in no leaks reported.
Note that this is intended for memory profiling only, and should not be used in a normal program.
#include <nngpp/nngpp.h>
#include <nngpp/protocol/req0.h>
#include <nngpp/protocol/rep0.h>
#include <cstdio>
int main() try {
{
nng::socket rep_sock = nng::rep::open();
rep_sock.listen( "tcp://localhost:8000" );
nng::socket req_sock = nng::req::open();
req_sock.dial( "tcp://localhost:8000" );
req_sock.send("hello");
nng::buffer rep_buf = rep_sock.recv();
if( rep_buf == "hello" ) {
rep_sock.send("world");
}
nng::buffer req_buf = req_sock.recv();
}
nng_fini();
}
catch( const nng::exception& e ) {
printf( "%s: %s\n", e.who(), e.what() );
return 1;
}
nqle commented
Sorry, I didn’t know about that but it makes sense now. Thanks! I’ll close the issue.