mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 16:06:09 +00:00
Problem: Out of memory condition not always checked
Solution: Use the appropriate assertion macro.
This commit is contained in:
parent
fe9f6b2837
commit
33e29bd383
@ -80,6 +80,8 @@ int zmq::gssapi_mechanism_base_t::encode_message (msg_t *msg_)
|
|||||||
flags |= 0x02;
|
flags |= 0x02;
|
||||||
|
|
||||||
uint8_t *plaintext_buffer = static_cast <uint8_t *>(malloc(msg_->size ()+1));
|
uint8_t *plaintext_buffer = static_cast <uint8_t *>(malloc(msg_->size ()+1));
|
||||||
|
alloc_assert(plaintext_buffer);
|
||||||
|
|
||||||
plaintext_buffer[0] = flags;
|
plaintext_buffer[0] = flags;
|
||||||
memcpy (plaintext_buffer+1, msg_->data(), msg_->size());
|
memcpy (plaintext_buffer+1, msg_->data(), msg_->size());
|
||||||
|
|
||||||
|
@ -416,6 +416,7 @@ void zmq::norm_engine_t::recv_data(NormObjectHandle object)
|
|||||||
{
|
{
|
||||||
// This is a new stream, so create rxState with zmq decoder, etc
|
// This is a new stream, so create rxState with zmq decoder, etc
|
||||||
rxState = new (std::nothrow) NormRxStreamState(object, options.maxmsgsize);
|
rxState = new (std::nothrow) NormRxStreamState(object, options.maxmsgsize);
|
||||||
|
errno_assert(rxState);
|
||||||
|
|
||||||
if (!rxState->Init())
|
if (!rxState->Init())
|
||||||
{
|
{
|
||||||
|
@ -84,6 +84,8 @@ int zmq::req_t::xsend (msg_t *msg_)
|
|||||||
|
|
||||||
// Copy request id before sending (see issue #1695 for details).
|
// Copy request id before sending (see issue #1695 for details).
|
||||||
uint32_t *request_id_copy = (uint32_t *) malloc (sizeof (uint32_t));
|
uint32_t *request_id_copy = (uint32_t *) malloc (sizeof (uint32_t));
|
||||||
|
zmq_assert (request_id_copy);
|
||||||
|
|
||||||
*request_id_copy = request_id;
|
*request_id_copy = request_id;
|
||||||
|
|
||||||
msg_t id;
|
msg_t id;
|
||||||
|
@ -533,6 +533,8 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
|||||||
if (*r_ != INVALID_SOCKET) {
|
if (*r_ != INVALID_SOCKET) {
|
||||||
size_t dummy_size = 1024 * 1024; // 1M to overload default receive buffer
|
size_t dummy_size = 1024 * 1024; // 1M to overload default receive buffer
|
||||||
unsigned char *dummy = (unsigned char *) malloc (dummy_size);
|
unsigned char *dummy = (unsigned char *) malloc (dummy_size);
|
||||||
|
wsa_assert (dummy);
|
||||||
|
|
||||||
int still_to_send = (int) dummy_size;
|
int still_to_send = (int) dummy_size;
|
||||||
int still_to_recv = (int) dummy_size;
|
int still_to_recv = (int) dummy_size;
|
||||||
while (still_to_send || still_to_recv) {
|
while (still_to_send || still_to_recv) {
|
||||||
|
@ -204,9 +204,13 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_, bool
|
|||||||
options.linger = parent_->get (ZMQ_BLOCKY)? -1: 0;
|
options.linger = parent_->get (ZMQ_BLOCKY)? -1: 0;
|
||||||
|
|
||||||
if (thread_safe)
|
if (thread_safe)
|
||||||
|
{
|
||||||
mailbox = new (std::nothrow) mailbox_safe_t(&sync);
|
mailbox = new (std::nothrow) mailbox_safe_t(&sync);
|
||||||
|
zmq_assert (mailbox);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
mailbox_t *m = new (std::nothrow) mailbox_t();
|
mailbox_t *m = new (std::nothrow) mailbox_t();
|
||||||
|
zmq_assert (m);
|
||||||
|
|
||||||
if (m->get_fd () != retired_fd)
|
if (m->get_fd () != retired_fd)
|
||||||
mailbox = m;
|
mailbox = m;
|
||||||
@ -1300,6 +1304,7 @@ void zmq::socket_base_t::start_reaping (poller_t *poller_)
|
|||||||
scoped_optional_lock_t sync_lock(thread_safe ? &sync : NULL);
|
scoped_optional_lock_t sync_lock(thread_safe ? &sync : NULL);
|
||||||
|
|
||||||
reaper_signaler = new (std::nothrow) signaler_t();
|
reaper_signaler = new (std::nothrow) signaler_t();
|
||||||
|
zmq_assert (reaper_signaler);
|
||||||
|
|
||||||
// Add signaler to the safe mailbox
|
// Add signaler to the safe mailbox
|
||||||
fd = reaper_signaler->get_fd();
|
fd = reaper_signaler->get_fd();
|
||||||
|
@ -212,6 +212,7 @@ void zmq::stream_engine_t::plug (io_thread_t *io_thread_,
|
|||||||
// Compile metadata.
|
// Compile metadata.
|
||||||
zmq_assert (metadata == NULL);
|
zmq_assert (metadata == NULL);
|
||||||
metadata = new (std::nothrow) metadata_t (properties);
|
metadata = new (std::nothrow) metadata_t (properties);
|
||||||
|
alloc_assert (metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.raw_notify) {
|
if (options.raw_notify) {
|
||||||
@ -861,7 +862,10 @@ void zmq::stream_engine_t::mechanism_ready ()
|
|||||||
|
|
||||||
zmq_assert (metadata == NULL);
|
zmq_assert (metadata == NULL);
|
||||||
if (!properties.empty ())
|
if (!properties.empty ())
|
||||||
|
{
|
||||||
metadata = new (std::nothrow) metadata_t (properties);
|
metadata = new (std::nothrow) metadata_t (properties);
|
||||||
|
alloc_assert (metadata);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ZMQ_BUILD_DRAFT_API
|
#ifdef ZMQ_BUILD_DRAFT_API
|
||||||
socket->event_handshake_succeed(endpoint, 0);
|
socket->event_handshake_succeed(endpoint, 0);
|
||||||
|
@ -77,6 +77,7 @@ unsigned long zmq_stopwatch_stop (void *watch_)
|
|||||||
void *zmq_threadstart(zmq_thread_fn* func, void* arg)
|
void *zmq_threadstart(zmq_thread_fn* func, void* arg)
|
||||||
{
|
{
|
||||||
zmq::thread_t* thread = new (std::nothrow) zmq::thread_t;
|
zmq::thread_t* thread = new (std::nothrow) zmq::thread_t;
|
||||||
|
alloc_assert(thread);
|
||||||
thread->start(func, arg);
|
thread->start(func, arg);
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user