Skip to content

Commit ddd0da2

Browse files
authored
Merge pull request #3476 from TomMD/fix/memory-leak
Request handling leaked memory. Depending on the application's use o…
2 parents 5368ae0 + 367cedb commit ddd0da2

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

RELICENSE/tommd.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Permission to Relicense under MPLv2
2+
3+
This is a statement by Thomas M. DuBuisson
4+
that grants permission to relicense its copyrights in the libzmq C++
5+
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2).
6+
7+
A portion of the commits made by the Github handle "tommd", with
8+
commit author "Thomas M. DuBuisson", are copyright of Thomas M. DuBuisson.
9+
This document hereby grants the libzmq project team to relicense libzmq,
10+
including all past, present and future contributions of the author listed above.
11+
12+
Thomas M. DuBuisson
13+
2019/04/11

src/req.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@
3636
#include "random.hpp"
3737
#include "likely.hpp"
3838

39-
extern "C" {
40-
static void free_id (void *data_, void *hint_)
41-
{
42-
LIBZMQ_UNUSED (hint_);
43-
free (data_);
44-
}
45-
}
46-
4739
zmq::req_t::req_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
4840
dealer_t (parent_, tid_, sid_),
4941
_receiving_reply (false),
@@ -81,22 +73,16 @@ int zmq::req_t::xsend (msg_t *msg_)
8173
if (_request_id_frames_enabled) {
8274
_request_id++;
8375

84-
// Copy request id before sending (see issue #1695 for details).
85-
uint32_t *request_id_copy =
86-
static_cast<uint32_t *> (malloc (sizeof (uint32_t)));
87-
zmq_assert (request_id_copy);
88-
89-
*request_id_copy = _request_id;
90-
9176
msg_t id;
92-
int rc =
93-
id.init_data (request_id_copy, sizeof (uint32_t), free_id, NULL);
77+
int rc = id.init_size (sizeof (uint32_t));
78+
memcpy (id.data (), &_request_id, sizeof (uint32_t));
9479
errno_assert (rc == 0);
9580
id.set_flags (msg_t::more);
9681

9782
rc = dealer_t::sendpipe (&id, &_reply_pipe);
98-
if (rc != 0)
83+
if (rc != 0) {
9984
return -1;
85+
}
10086
}
10187

10288
msg_t bottom;

0 commit comments

Comments
 (0)