[Openais] Re: evt message leak patch

Steven Dake sdake at mvista.com
Thu Jul 29 16:02:04 PDT 2004


Mark

I have fixed the amf in a similiar fashion for the dispatch, but I
haven't done the destructor yet.

I'm not a big fan of for(;;) operations but I guess we can come back to
it later when we have more time.

I noticed after looking through all the code for the leak that the way
the evt lib was using RecvQueue was wrong.  I had meant that a buffer of
large enough size to handle a message for any response was passed in to
the function.

I changed the RecvQueue function so it uses a large buffer area on the
stack and recvs the message, then if the message is for the responder,
it copies it to the responder.  This is a little more ineffecient but
more sane for the API users and does what you might expect.

I've merged in those changes.

Thanks
-steve

On Thu, 2004-07-29 at 15:24, Mark Haverkamp wrote:
> Here is what I think will plug the message leak.  Both in the destructor
> and the dispatch function.
> 
> Mark.
> 
> 
> ===== lib/evt.c 1.1 vs edited =====
> --- 1.1/lib/evt.c	2004-07-29 11:41:40 -07:00
> +++ edited/lib/evt.c	2004-07-29 15:22:44 -07:00
> @@ -180,11 +180,32 @@
>  static void evtHandleInstanceDestructor(void *instance)
>  {
>  	struct event_instance *evti = instance;
> +	void *msg;
> +	int empty;
> +
> +	/*
> +	 * Empty out the queue if there are any pending messages
> +	 */
> +	while (1) {
> +		saQueueIsEmpty(&evti->ei_inq, &empty);	
> +		if (empty) {
> +			break;
> +		}
> +		saQueueItemGet(&evti->ei_inq, &msg);
> +		saQueueItemRemove(&evti->ei_inq);
> +		free(msg);
> +	}
>  
> +	/*
> +	 * clean up the queue itself
> +	 */
>  	if (evti->ei_inq.items) {
>  			free(evti->ei_inq.items);
>  	}
>  
> +	/*
> +	 * Disconnect from the server
> +	 */
>  	if (evti->ei_fd != -1) {
>  		shutdown(evti->ei_fd, 0);
>  		close(evti->ei_fd);
> @@ -409,6 +430,7 @@
>  			msg = *queue_msg;
>  			memcpy(&dispatch_data, msg, msg->size);
>  			saQueueItemRemove(&evti->ei_inq);
> +			free(msg);
>  		} else {
>  			/*
>  			 * Queue empty, read response from socket




More information about the Openais mailing list