You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kg...@apache.org on 2016/06/02 15:31:08 UTC
[1/2] qpid-proton git commit: PROTON-1219: fix memory leaks in
reactor examples.
Repository: qpid-proton
Updated Branches:
refs/heads/0.13.x 69e9c9f55 -> 4ca0533c4
PROTON-1219: fix memory leaks in reactor examples.
(cherry picked from commit 47c778e18893f96e2c0b8d17f2d3f87d116b70b3)
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/737ffd2f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/737ffd2f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/737ffd2f
Branch: refs/heads/0.13.x
Commit: 737ffd2f4c98f52c30b39bada5ec3d39be2e5ab9
Parents: 69e9c9f
Author: Ken Giusti <kg...@apache.org>
Authored: Tue May 31 14:56:22 2016 -0400
Committer: Ken Giusti <kg...@apache.org>
Committed: Thu Jun 2 11:15:50 2016 -0400
----------------------------------------------------------------------
examples/c/reactor/receiver.c | 47 +++++++++++++++++++++++---------------
examples/c/reactor/sender.c | 6 ++++-
2 files changed, 34 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/737ffd2f/examples/c/reactor/receiver.c
----------------------------------------------------------------------
diff --git a/examples/c/reactor/receiver.c b/examples/c/reactor/receiver.c
index b13c5a0..524c78c 100644
--- a/examples/c/reactor/receiver.c
+++ b/examples/c/reactor/receiver.c
@@ -102,26 +102,33 @@ static void event_handler(pn_handler_t *handler,
pn_delivery_t *dlv = pn_event_delivery(event);
if (pn_delivery_readable(dlv) && !pn_delivery_partial(dlv)) {
// A full message has arrived
- if (!quiet && pn_delivery_pending(dlv) < MAX_SIZE) {
- // try to decode the message body
+ if (!quiet) {
+ static char buffer[MAX_SIZE];
+ size_t len;
pn_bytes_t bytes;
bool found = false;
- static char buffer[MAX_SIZE];
- size_t len = pn_link_recv(pn_delivery_link(dlv), buffer, MAX_SIZE);
- pn_message_clear(data->message);
- // decode the raw data into the message instance
- if (pn_message_decode(data->message, buffer, len) == PN_OK) {
- // Assuming the message came from the sender example, try
- // to parse out a single string from the payload
- //
- int rc = pn_data_scan(pn_message_body(data->message)
- , "?S", &found, &bytes);
- if (!rc && found) {
- fprintf(stdout, "Message: [%.*s]\n",
- (int)bytes.size, bytes.start);
- } else {
- fprintf(stdout, "Message received!\n");
+
+ // try to decode the message body
+ if (pn_delivery_pending(dlv) < MAX_SIZE) {
+ // read in the raw data
+ len = pn_link_recv(pn_delivery_link(dlv), buffer, MAX_SIZE);
+ if (len > 0) {
+ // decode it into a proton message
+ pn_message_clear(data->message);
+ if (PN_OK == pn_message_decode(data->message, buffer,
+ len)) {
+ // Assuming the message came from the sender
+ // example, try to parse out a single string from
+ // the payload
+ //
+ pn_data_scan(pn_message_body(data->message), "?S",
+ &found, &bytes);
+ }
}
+ }
+ if (found) {
+ fprintf(stdout, "Message: [%.*s]\n", (int)bytes.size,
+ bytes.start);
} else {
fprintf(stdout, "Message received!\n");
}
@@ -216,7 +223,9 @@ int main(int argc, char** argv)
/* Attach the pn_handshaker() handler. This handler deals with endpoint
* events from the peer so we don't have to.
*/
- pn_handler_add(handler, pn_handshaker());
+ pn_handler_t *handshaker = pn_handshaker();
+ pn_handler_add(handler, handshaker);
+ pn_decref(handshaker);
/* command line options */
opterr = 0;
@@ -249,6 +258,7 @@ int main(int argc, char** argv)
pn_url_get_port(url),
handler);
pn_decref(url);
+ pn_decref(handler);
// the container name should be unique for each client
pn_connection_set_container(conn, container);
@@ -268,6 +278,7 @@ int main(int argc, char** argv)
* pn_reactor_process() will return false.
*/
}
+ pn_decref(reactor);
return 0;
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/737ffd2f/examples/c/reactor/sender.c
----------------------------------------------------------------------
diff --git a/examples/c/reactor/sender.c b/examples/c/reactor/sender.c
index 02828ac..850b16f 100644
--- a/examples/c/reactor/sender.c
+++ b/examples/c/reactor/sender.c
@@ -230,7 +230,9 @@ int main(int argc, char** argv)
/* Attach the pn_handshaker() handler. This handler deals with endpoint
* events from the peer so we don't have to.
*/
- pn_handler_add(handler, pn_handshaker());
+ pn_handler_t *handshaker = pn_handshaker();
+ pn_handler_add(handler, handshaker);
+ pn_decref(handshaker);
/* command line options */
opterr = 0;
@@ -300,6 +302,7 @@ int main(int argc, char** argv)
pn_url_get_port(url),
handler);
pn_decref(url);
+ pn_decref(handler);
// the container name should be unique for each client
pn_connection_set_container(conn, container);
@@ -319,6 +322,7 @@ int main(int argc, char** argv)
* pn_reactor_process() will return false.
*/
}
+ pn_decref(reactor);
return 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/2] qpid-proton git commit: PROTON-1219: fix windows errors and
signed/unsigned issues
Posted by kg...@apache.org.
PROTON-1219: fix windows errors and signed/unsigned issues
(cherry picked from commit 5cd3d4ee51d8ed8d22bbdc5f782eb88d6b181c06)
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/4ca0533c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/4ca0533c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/4ca0533c
Branch: refs/heads/0.13.x
Commit: 4ca0533c418f506c3b6fc554edefc8ecff9fdd6d
Parents: 737ffd2
Author: Ken Giusti <kg...@apache.org>
Authored: Wed Jun 1 10:22:35 2016 -0400
Committer: Ken Giusti <kg...@apache.org>
Committed: Thu Jun 2 11:17:44 2016 -0400
----------------------------------------------------------------------
examples/c/reactor/receiver.c | 18 ++++++++++--------
examples/c/reactor/sender.c | 25 +++++++++++++------------
2 files changed, 23 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4ca0533c/examples/c/reactor/receiver.c
----------------------------------------------------------------------
diff --git a/examples/c/reactor/receiver.c b/examples/c/reactor/receiver.c
index 524c78c..35c5a70 100644
--- a/examples/c/reactor/receiver.c
+++ b/examples/c/reactor/receiver.c
@@ -47,8 +47,8 @@ static const int CAPACITY = 100;
//
typedef struct {
int count; // # of messages to receive before exiting
- char *source; // name of the source node to receive from
- pn_message_t *message; // holds the received message
+ const char *source; // name of the source node to receive from
+ pn_message_t *message; // holds the received message
} app_data_t;
// helper to pull pointer to app_data_t instance out of the pn_handler_t
@@ -104,7 +104,7 @@ static void event_handler(pn_handler_t *handler,
// A full message has arrived
if (!quiet) {
static char buffer[MAX_SIZE];
- size_t len;
+ ssize_t len;
pn_bytes_t bytes;
bool found = false;
@@ -197,8 +197,8 @@ static void usage(void)
int main(int argc, char** argv)
{
- char *address = "localhost";
- char *container = "ReceiveExample";
+ const char *address = "localhost";
+ const char *container = "ReceiveExample";
int c;
pn_reactor_t *reactor = NULL;
pn_url_t *url = NULL;
@@ -223,9 +223,11 @@ int main(int argc, char** argv)
/* Attach the pn_handshaker() handler. This handler deals with endpoint
* events from the peer so we don't have to.
*/
- pn_handler_t *handshaker = pn_handshaker();
- pn_handler_add(handler, handshaker);
- pn_decref(handshaker);
+ {
+ pn_handler_t *handshaker = pn_handshaker();
+ pn_handler_add(handler, handshaker);
+ pn_decref(handshaker);
+ }
/* command line options */
opterr = 0;
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/4ca0533c/examples/c/reactor/sender.c
----------------------------------------------------------------------
diff --git a/examples/c/reactor/sender.c b/examples/c/reactor/sender.c
index 850b16f..6c3cdb3 100644
--- a/examples/c/reactor/sender.c
+++ b/examples/c/reactor/sender.c
@@ -43,11 +43,11 @@ static int quiet = 0;
// holds configuration and state information.
//
typedef struct {
- int count; // # messages to send
- int anon; // use anonymous link if true
- char *target; // name of destination target
- char *msg_data; // pre-encoded outbound message
- int msg_len; // bytes in msg_data
+ int count; // # messages to send
+ int anon; // use anonymous link if true
+ const char *target; // name of destination target
+ char *msg_data; // pre-encoded outbound message
+ size_t msg_len; // bytes in msg_data
} app_data_t;
// helper to pull pointer to app_data_t instance out of the pn_handler_t
@@ -201,10 +201,9 @@ static void usage(void)
int main(int argc, char** argv)
{
- char *address = "localhost";
- char *msgtext = "Hello World!";
- char *container = "SendExample";
- int anon = 0;
+ const char *address = "localhost";
+ const char *msgtext = "Hello World!";
+ const char *container = "SendExample";
int c;
pn_message_t *message = NULL;
pn_data_t *body = NULL;
@@ -230,9 +229,11 @@ int main(int argc, char** argv)
/* Attach the pn_handshaker() handler. This handler deals with endpoint
* events from the peer so we don't have to.
*/
- pn_handler_t *handshaker = pn_handshaker();
- pn_handler_add(handler, handshaker);
- pn_decref(handshaker);
+ {
+ pn_handler_t *handshaker = pn_handshaker();
+ pn_handler_add(handler, handshaker);
+ pn_decref(handshaker);
+ }
/* command line options */
opterr = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org