From 16b2db606233053420575c140a72edd53814f55b Mon Sep 17 00:00:00 2001 From: Jonathan Reams Date: Sun, 31 Aug 2014 14:02:57 -0400 Subject: [PATCH] Clean up after using randombytes from libsodium When Curve authentication is used, libsodium opens a file descriptor to /dev/urandom to generate random bytes. When the ZMQ context terminates, it should ensure that file gets closed. --- src/ctx.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ctx.cpp b/src/ctx.cpp index f7b432a0..a06f3624 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -35,6 +35,10 @@ #include "err.hpp" #include "msg.hpp" +#ifdef HAVE_LIBSODIUM +#include +#endif + #define ZMQ_CTX_TAG_VALUE_GOOD 0xabadcafe #define ZMQ_CTX_TAG_VALUE_BAD 0xdeadbeef @@ -89,6 +93,12 @@ zmq::ctx_t::~ctx_t () // corresponding io_thread/socket objects. free (slots); + // If we've done any Curve encryption, we may have a file handle + // to /dev/urandom open that needs to be cleaned up. +#ifdef HAVE_LIBSODIUM + randombytes_close(); +#endif + // Remove the tag, so that the object is considered dead. tag = ZMQ_CTX_TAG_VALUE_BAD; }