changeset 3:44e4b80bdf97

FIX: malloc error on freeing OSC address after using extended message handler (see osc_add_method_x)
author samer
date Wed, 01 Feb 2012 15:42:55 +0000
parents 6c1ba6bf9f96
children 8a71c55816be
files c/plosc.c
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/c/plosc.c	Tue Jan 31 15:53:45 2012 +0000
+++ b/c/plosc.c	Wed Feb 01 15:42:55 2012 +0000
@@ -633,26 +633,35 @@
 {
 	term_t goal  = PL_new_term_ref();
 	term_t term0 = PL_new_term_refs(5);
-	int rc=1;
+	int rc;
 
 	lo_timetag ts = lo_message_get_timestamp(msg);
 	lo_address sender = lo_message_get_source(msg);
-	// printf("osc tt: %u s +  %u micros\n",ts.sec,ts.frac);
+	lo_address sender_copy;
+
+	{	
+		const char *host=lo_address_get_hostname(sender);
+		const char *port=lo_address_get_port(sender);
+		sender_copy=lo_address_new(host,port);
+	}
 
 	PL_recorded((record_t)user_data,goal); // retrieve the goal term
 	PL_put_term(term0,goal); // term_t goal encoded in user_data
 	PL_put_atom_chars(term0+3,path);
 
-	if (ts.sec==0u) PL_put_atom(term0+2,osc_immed);
+
+	if (ts.sec==0u) rc=PL_put_atom(term0+2,osc_immed);
 	else { 
 		rc=PL_unify_term( term0+2, PL_FUNCTOR, osc_ts_2, 
 				PL_INT64, (int64_t)ts.sec,
 				PL_INT64, (int64_t)ts.frac);
 	}
+
 	// PL_put_float(term0+2, (double)(ts.sec-2208988800u) + ts.frac/4294967296.0);
 
 	return !( rc
-	       && unify_addr(term0+1,sender)
+	       && unify_addr(term0+1,sender_copy)
+		 //	 && PL_put_atom_chars(term0+1,"orac")
 	       && unify_msg_args(PL_copy_term_ref(term0+4),types,argv,argc) 
 			 && PL_call_predicate(NULL,PL_Q_NORMAL,call5,term0));
 }