Interface Patch

Brian Aker brian at tangent.org
Mon Feb 4 15:51:47 UTC 2008


Hi!

On Feb 4, 2008, at 1:49 AM, Tomash Brechko wrote:

> On Mon, Feb 04, 2008 at 00:44:49 -0800, Brian Aker wrote:
>> This do { } while loop won't close sfd_list[0] (and the first if()
> would also skip over the just created socket too).  Use the loop from
> my mail ;).

Your loop does not work:
                   ++sfd_ptr;
                   while (sfd_ptr != sfd_list) {
                       --sfd_ptr;
                       close(*sfd_ptr);
                   }

You incremented first to a pointer that may walk off the end of the  
array. You then decremented back to the pointer that is current (which  
is not set).
Then you loop to close and never touch the final member of the array.

In my haste I left the increment wrong as well:
                     do {
                         --sfd_ptr;
                         close(*sfd_ptr);
                     } while (sfd_ptr != sfd_list);

This way you move past the current pointer you are on (since it is not  
valid) and then jump to the next.
You close() and move on. The final pointer will be caught and then  
when you hit the while on the last pointer (after you have closed it),  
you will exit.

Cheers,
	-Brian
--
_______________________________________________________
Brian "Krow" Aker, brian at tangent.org
Seattle, Washington
http://krow.net/                     <-- Me
http://tangent.org/                <-- Software
http://exploitseattle.com/    <-- Fun
_______________________________________________________
You can't grep a dead tree.




More information about the memcached mailing list