Description: Make session cleanup more robust
 Make cs_list_remove delete multiple members of cs_list matching the given
 state if present, otherwise cs_list_interrupt may crash on exit.
Author: Colin Watson <cjwatson@ubuntu.com>
Forwarded: no
Last-Update: 2014-12-02

Index: b/ext/patron/session_ext.c
===================================================================
--- a/ext/patron/session_ext.c
+++ b/ext/patron/session_ext.c
@@ -128,8 +128,10 @@
   struct curl_state_list *item = NULL;
 
   assert(state != NULL);
-  SGLIB_LIST_FIND_MEMBER(struct curl_state_list, cs_list, state, CS_LIST_COMPARATOR, next, item);
-  if (item) {
+  for (;;) {
+    SGLIB_LIST_FIND_MEMBER(struct curl_state_list, cs_list, state, CS_LIST_COMPARATOR, next, item);
+    if (!item)
+      break;
     SGLIB_LIST_DELETE(struct curl_state_list, cs_list, item, next);
     ruby_xfree(item);
   }
