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/05/31 19:09:23 UTC
[1/2] qpid-proton git commit: NO-JIRA: fix memory leaks in reactor
examples.
Repository: qpid-proton
Updated Branches:
refs/heads/master 9a7b2cf03 -> 47c778e18
NO-JIRA: fix memory leaks in reactor examples.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/47c778e1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/47c778e1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/47c778e1
Branch: refs/heads/master
Commit: 47c778e18893f96e2c0b8d17f2d3f87d116b70b3
Parents: 34ae9ea
Author: Ken Giusti <kg...@apache.org>
Authored: Tue May 31 14:56:22 2016 -0400
Committer: Ken Giusti <kg...@apache.org>
Committed: Tue May 31 15:02:55 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/47c778e1/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/47c778e1/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: NO-JIRA: cleanup vhost handling issues
found by Coverity
Posted by kg...@apache.org.
NO-JIRA: cleanup vhost handling issues found by Coverity
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/34ae9ea9
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/34ae9ea9
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/34ae9ea9
Branch: refs/heads/master
Commit: 34ae9ea9e856d15c483ed8b98582c3e0bc665a85
Parents: 9a7b2cf
Author: Ken Giusti <kg...@apache.org>
Authored: Tue May 31 13:35:23 2016 -0400
Committer: Ken Giusti <kg...@apache.org>
Committed: Tue May 31 15:02:55 2016 -0400
----------------------------------------------------------------------
.../java/org/apache/qpid/proton/reactor/impl/IOHandler.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/34ae9ea9/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
index c0e51d5..30ad246 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/reactor/impl/IOHandler.java
@@ -87,9 +87,12 @@ public class IOHandler extends BaseHandler {
if (vhost == null) {
// setHostname never called, use the host from the connection's
// socket address as the default virtual host:
- Address addr = new Address(reactor.getConnectionAddress(connection));
- connection.setHostname(addr.getHost());
- } else if (vhost == "") {
+ String conAddr = reactor.getConnectionAddress(connection);
+ if (conAddr != null) {
+ Address addr = new Address(conAddr);
+ connection.setHostname(addr.getHost());
+ }
+ } else if (vhost.isEmpty()) {
// setHostname called explictly with a null string. This allows
// the application to completely avoid sending a virtual host
// name
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org