72 - amq_content_basic_new() causes seg fault if not connected to broker

Reported by mjeungmjeung (1250121043|%O ago)

If you call amq_content_basic_new() before you're connected to the broker, the program will seg-fault.

I'm not really sure what the desired behavior should be, since this basically amounts to incorrect usage of the WireAPI.

However, perhaps instead of a seg-fault, the WireAPI could exit with a helpful error code?

To reproduce, I just grabbed the im_sender.c application and commented out the section where the code connects.

Backtrace:

(gdb) bt full
#0 pthread_mutex_lock (mutex=0x8) at pthread_mutex_lock.c:50
__PRETTY_FUNCTION
= "__pthread_mutex_lock"
type = <value optimized out>
#1 0x000000000044de23 in icl_cache_initialise () at icl_cache.c:624
No locals.
#2 0x000000000044e3ec in icl_cache_get (size=4464) at icl_cache.c:441
old_cache = <value optimized out>
self = <value optimized out>
#3 0x0000000000408b2e in amq_content_basic_cache_initialise () at amq_content_basic.c:5985
No locals.
#4 amq_content_basic_alloc_ () at amq_content_basic.c:5654
No locals.
#5 amq_content_basic_new_ () at amq_content_basic.c:400
self = <value optimized out>
#6 0x0000000000403ff5 in main ()
No symbol table info available.
Current language: auto; currently minimal

To reproduce, compile the below code, run it, type something in, then hit enter. (You have to give it a couple of command-line arguments to run it.)

#include "base.h"
#include "amq_client_connection.h"
#include "amq_client_session.h"

int main (int argc, char *argv [])
{
amq_client_connection_t
*connection;
amq_client_session_t
*session;
icl_longstr_t
*auth_data;
amq_content_basic_t
*content;
char
message_text [1024];
char
*message_body;
assert (argc == 4);

// Initialise system
//icl_system_initialise (argc, argv);

// Open a connection
//auth_data = amq_client_connection_auth_plain ("guest", "guest");
//connection = amq_client_connection_new (
// argv [1], "/", auth_data, "im_sender", 0, 30000);
//assert (connection);
//icl_longstr_destroy (&auth_data);

// Open a channel
//session = amq_client_session_new (connection);
//assert (session);

while (1) {
// Read one line from stdin
fgets (message_text, sizeof (message_text), stdin);
// Exit the loop if Ctrl+C is encountered
//if (!connection->alive)
// break;
// Create the message body
message_body =
malloc (strlen (argv [3]) + 2 + strlen (message_text) + 1);
assert (message_body);
sprintf (message_body, "%s: %s", argv [3], message_text);
// Create the message itself
content = amq_content_basic_new ();
amq_content_basic_set_body (content, message_body,
strlen (message_body), free);
// Send the message
amq_client_session_basic_publish (
session, // session
content, // content to send
0, // ticket
"amq.direct", // exchange to send message to
argv [2], // routing-key
FALSE, // mandatory
FALSE); // immediate
// Release the message
amq_content_basic_unlink (&content);
}
// Close the channel
amq_client_session_destroy (&session);
// Close the connection
amq_client_connection_destroy (&connection);
// Uninitialise system
icl_system_terminate ();
return 0;
}

Attachments:

No files attached to this page.

Comments

Add a New Comment

Edit | Files | Tags | Print

rating: 0+x

Who's following this issue?

pieterhpieterh
martin_sustrikmartin_sustrik
mjeungmjeung
CybariteCybarite
Watch: site | category | page

Submitted by mjeungmjeung

Use one of these tags to say what kind of issue it is:

  • issue - a fault in the software or the packaging or the documentation.
  • change - a change or feature request.

Use one of these tags to say what state the issue is in:

  • open - a new, open issue.
  • closed - issue has been closed.
  • rejected - the issue has been rejected.

Use one of these tags to say how urgent the issue is:

  • fatal - the issue is stopping all work.
  • urgent - it's urgent.

All open

89 - multi-threaded client connection failure (17 Nov 2012 16:28) [open]
87 - Zyre returns incomplete XML (26 Apr 2010 08:15) [open]
86 - SFL 'random(num)' macro is wrong in sfl.h (31 Mar 2010 09:23) [open]
85 - Zyre does not start on Solaris (23 Mar 2010 01:29) [open]
84 - OpenAMQ JMS - AMQTopic constructor use HEADER name and class instead of TOPIC (28 Jan 2010 17:04) [open]
83 - WireAPI: How to 'override' signal handlers? (14 Jan 2010 17:33) [open]
82 - Opf Classes Cannot Accept Default Values With Characte (06 Jan 2010 09:34) [open]
81 - AMQP Topic Exhange Routing (29 Dec 2009 00:21) [open]
80 - OpenAMQ reports malformed frame on 0-9-1 queue.unbind (20 Nov 2009 12:33) [open]
79 - AMQ Server crashing if subscribe topic is set as #.# (30 Oct 2009 06:11) [open]
78 - Error while publishing the messages faster (30 Oct 2009 05:57) [open]
77 - Tuning for latency (28 Oct 2009 16:47) [open]
76 - New user forum (28 Oct 2009 11:29) [change open]
74 - Simulaneous connect/disconnect from multiple threads crashes (03 Sep 2009 15:32) [open]
73 - Topic Exchange not sending a message to XXX.* (25 Aug 2009 21:10) [open]
72 - amq_content_basic_new() causes seg fault if not connected to broker (12 Aug 2009 23:50) [open]
71 - zyre bugs (06 Aug 2009 09:33) [open]
69 - OpenAMQ and Zyre (15 Jul 2009 11:27) [open]
68 - Change names of max and min source code macros (10 Jul 2009 16:52) [open]
67 - Server crash when multiple consumers ack on shared queue (26 Jun 2009 11:35) [open]

page 1 of 212next »

Most recent