Websocket stdio / websocketd experiment
authorBill Erickson <berickxx@gmail.com>
Mon, 11 Jun 2018 01:08:21 +0000 (21:08 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Jun 2018 01:08:21 +0000 (21:08 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
src/websocket-stdio/osrf-websocket-stdio.c

index 6427ef6..f32e28c 100644 (file)
@@ -238,6 +238,7 @@ static void relay_stdin_message(const char* msg_string) {
     const char *service = NULL;
     const char *thread = NULL;
     const char *log_xid = NULL;
+    char *tmp_recip = NULL;
     char *msg_body = NULL;
     char *recipient = NULL;
 
@@ -310,14 +311,19 @@ static void relay_stdin_message(const char* msg_string) {
         "WS relaying message to opensrf thread=%s, recipient=%s",
             thread, recipient);
 
-    msg_body = extract_inbound_messages(
-        service, thread, recipient, osrf_msg);
+    // 'recipient' will be freed in extract_inbound_messages
+    // during a DISCONNECT call.  Retain a local copy.
+    tmp_recip = strdup(recipient);
+
+    msg_body = extract_inbound_messages(service, thread, recipient, osrf_msg);
 
     osrfLogInternal(OSRF_LOG_MARK,
         "WS relaying inbound message: %s", msg_body);
 
     transport_message *tmsg = message_init(
-        msg_body, NULL, thread, recipient, NULL);
+        msg_body, NULL, thread, tmp_recip, NULL);
+
+    free(tmp_recip);
 
     message_set_osrf_xid(tmsg, osrfLogGetXid());