rem: shm_free( buf.s );
add: AAAFreeMessage( &msg  );
context: void *server_worker(void *attr){	str               buf;	AAAMessage        *msg;	struct peer_chain *pc;	struct aaa_module *mod;	struct trans      *tr;	struct peer       *in_peer;	int               res;	while (1) {		/* read a mesage from the queue */		if (get_from_queue( &buf, &in_peer )==-1) {			usleep(500);			continue;		}		/* process the message */		if ( is_req( msg ) ) {			/* request*/			msg = AAATranslateMessage( buf.s, buf.len );			if (!msg) {				LOG(L_ERR,"ERROR:server_worker: dropping message!\n");				shm_free( buf.s );				continue;			}			if (!msg->sessionId || !msg->orig_host || !msg->orig_realm ||			!msg->dest_realm) {				LOG(L_ERR,"ERROR:server_worker: message without sessionId/"					"OriginHost/OriginRealm/DestinationRealm AVP received "					"-> droping!\n");				send_error_reply( msg, AAA_MISSING_AVP);				AAAFreeMessage( &msg );				continue;			}			/*-> what should I do with it? */			res = get_req_destination( msg, &pc, &mod );			if (res!=0) {				/* it was an error -> I have to send back an error answer */				send_error_reply( msg, res);				AAAFreeMessage( &msg );				continue;			}			/* process the request */			if (mod) {				/* it's a local request */				/* if the server is statefull, I have to call here the session				 * state machine for the incoming request TO DO */				msg->sId = &(msg->sessionId->data);				/*run the handler for this module */				mod->exports->mod_msg( msg, 0);			} else {				/* forward the request -> build a transaction for it */				tr = create_transaction( &(msg->buf), in_peer);				if (!tr) {					LOG(L_ERR,"ERROR:server_worker: dropping request!\n");					AAAFreeMessage( &msg );					continue;				}				/* remember the received hop_by_hop-Id */				tr->orig_hopbyhopId = msg->hopbyhopId;				/* am I Foreign server for this request? */				if ( msg->orig_host->data.len==in_peer->aaa_identity.len &&				!strncmp(msg->orig_host->data.s,in_peer->aaa_identity.s,				in_peer->aaa_identity.len) )					tr->info = I_AM_FOREIGN_SERVER;				else					tr->info = I_AM_NOT_FOREIGN_SERVER;				/* send it out */				for(;pc;pc=pc->next) {					if ( (res=send_req_to_peer( tr, pc->p))!=-1) {						/* success -> start the timeout timer */						add_to_timer_list( &(tr->timeout) , tr_timeout_timer ,							get_ticks()+TR_TIMEOUT_TIMEOUT );						break;					}				}				tr->req = 0;				if (res==-1) {					LOG(L_ERR,"ERROR:server_worker: unable to forward "						"request\n");					send_error_reply( msg, AAA_UNABLE_TO_DELIVER);				}			}			/* free the mesage (along with the buffer) */			AAAFreeMessage( &msg  );		} else {			/* response -> performe transaction lookup and remove it from 			 * hash table */			tr = transaction_lookup(in_peer,msg->endtoendId,msg->hopbyhopId);			if (!tr) {				LOG(L_ERR,"ERROR:server_worker: unexpected answer received "					"(without sending any request)!\n");				shm_free( buf.s );				continue;			}			/* stop the transaction timeout */			rmv_from_timer_list( &(tr->timeout) );			/* parse the reply */			msg = AAATranslateMessage( buf.s, buf.len );			if (!msg) {				LOG(L_ERR,"ERROR:server_worker: dropping message!\n");				shm_free( buf.s );				continue;			}			if (tr->in_peer) {				/* I have to forward the reply downstream */				msg->hopbyhopId = tr->orig_hopbyhopId;				((unsigned int*)msg->buf.s)[3] = tr->orig_hopbyhopId;				/* am I Foreign server for this reply? */				if (tr->info==I_AM_FOREIGN_SERVER) {					mod = find_module(msg->applicationId);					if (mod)						mod->exports->mod_msg( msg, 0);				}				/* send the rely */				if (send_res_to_peer( &msg->buf, tr->in_peer)==-1) {					LOG(L_ERR,"ERROR:server_worker: forwarding reply "						"failed\n");				}			} else {				/* look like being a reply to a local request */				LOG(L_ERR,"BUG:server_worker: some reply to a local request "					"received; but I don't send requests!!!!\n");			}			/* destroy the transaction */			destroy_transaction( tr );			/* free the mesage (along with the buffer) */			AAAFreeMessage( &msg  );		}	}	return 0;}