Skip to content

Commit

Permalink
plugged some memory leaks found with valgrind
Browse files Browse the repository at this point in the history
  • Loading branch information
ekarak committed May 24, 2012
1 parent 9c52818 commit ab695a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
41 changes: 20 additions & 21 deletions BoostStomp.cpp
Expand Up @@ -83,8 +83,8 @@ namespace STOMP {
m_io_service->stop();
// then interrupt the worker thread
worker_thread->interrupt();
//delete m_heartbeat_timer;
//delete worker_thread;
// delete m_heartbeat_timer; // no need, its a shared_ptr
delete worker_thread;
}

// ----------------------------
Expand Down Expand Up @@ -226,13 +226,12 @@ namespace STOMP {
std::size_t bodysize = 0;
try {
//debug_print("handle_stomp_read_headers");
m_rcvd_frame = new Frame(stomp_response, cmd_map);
m_rcvd_frame = new Frame(stomp_response, cmd_map); // freed by consume_frame
hdrmap& _headers = m_rcvd_frame->headers();
// if the frame headers contain 'content-length', use that to call the proper async_read overload
if (_headers.find("content-length") != _headers.end()) {
string& content_length = _headers["content-length"];
debug_print(boost::format("received response (command+headers: %1% bytes, content-length: %2%)") % stomp_response.size() % content_length );
sleep(1);
bodysize = lexical_cast<size_t>(content_length);
}
start_stomp_read_body(bodysize);
Expand All @@ -257,7 +256,7 @@ namespace STOMP {
void BoostStomp::start_stomp_read_body(std::size_t bodysize)
// -----------------------------------------------
{
debug_print("start_stomp_read_body");
//debug_print("start_stomp_read_body");
// Start an asynchronous operation to read at least the STOMP frame body
if (bodysize == 0) {
boost::asio::async_read_until(
Expand Down Expand Up @@ -301,6 +300,22 @@ namespace STOMP {
}
}

// ------------------------------------------
void BoostStomp::consume_received_frame()
// ------------------------------------------
{
if (m_rcvd_frame != NULL) {
pfnStompCommandHandler_t handler = cmd_map[m_rcvd_frame->command()];
if (handler != NULL) {
//debug_print(boost::format("-- consume_frame: calling %1% command handler") % m_rcvd_frame->command());
// call STOMP command handler
(this->*handler)();
}
delete m_rcvd_frame;
}
m_rcvd_frame = NULL;
};

// ------------------------------------------------
// ---------- OUTPUT ACTOR SETUP ------------------
// ------------------------------------------------
Expand Down Expand Up @@ -374,22 +389,6 @@ namespace STOMP {
}
}

// ------------------------------------------
void BoostStomp::consume_received_frame()
// ------------------------------------------
{
if (m_rcvd_frame != NULL) {
pfnStompCommandHandler_t handler = cmd_map[m_rcvd_frame->command()];
if (handler != NULL) {
//debug_print(boost::format("-- consume_frame: calling %1% command handler") % m_rcvd_frame->command());
// call STOMP command handler
(this->*handler)();
}
delete m_rcvd_frame;
}
m_rcvd_frame = NULL;
};

//-----------------------------------------
void BoostStomp::process_CONNECTED()
//-----------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion Main.cpp
Expand Up @@ -105,8 +105,9 @@ int main(int argc, char *argv[]) {
headers2["count"] = to_string<int>(i);
stomp_client->send(notifications_topic, headers2, "");
};
sleep(4);
sleep(2);
stomp_client->stop();
delete stomp_client;
}
catch (std::exception& e)
{
Expand Down

0 comments on commit ab695a5

Please sign in to comment.