diff mcabber/src/jab_iq.c @ 705:603b43e4f56a

Fix a bug in iqs_check_timeout() There was a possible segfault because g_slist_next() could be called with a freed element. (Note: this function is never called yet, anyway...) While I'm changing it, I'm changing the prototype so that iqs_check_timeout() takes now_t as a parameter; it will save a time() call.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 18 Feb 2006 15:04:17 +0100
parents 4118a66f2c02
children 413e95f3051a
line wrap: on
line diff
--- a/mcabber/src/jab_iq.c	Sat Feb 18 12:05:46 2006 +0100
+++ b/mcabber/src/jab_iq.c	Sat Feb 18 15:04:17 2006 +0100
@@ -124,16 +124,18 @@
   return 0;
 }
 
-void iqs_check_timeout(void)
+void iqs_check_timeout(time_t now_t)
 {
   GSList *p;
   iqs *i;
-  time_t now_t;
 
-  time(&now_t);
+  p = iqs_list;
+  while (p) {
+    i = p->data;
+    // We must get next iqs element now because the current one
+    // could be freed.
+    p = g_slist_next(p);
 
-  for (p = iqs_list; p; p = g_slist_next(p)) {
-    i = p->data;
     if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) ||
         (i->ts_expire && now_t > i->ts_expire)) {
       iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT);