Mercurial > ~mikael > mcabber > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
704:4118a66f2c02 | 705:603b43e4f56a |
---|---|
122 | 122 |
123 iqs_del(iqid); | 123 iqs_del(iqid); |
124 return 0; | 124 return 0; |
125 } | 125 } |
126 | 126 |
127 void iqs_check_timeout(void) | 127 void iqs_check_timeout(time_t now_t) |
128 { | 128 { |
129 GSList *p; | 129 GSList *p; |
130 iqs *i; | 130 iqs *i; |
131 time_t now_t; | 131 |
132 | 132 p = iqs_list; |
133 time(&now_t); | 133 while (p) { |
134 | |
135 for (p = iqs_list; p; p = g_slist_next(p)) { | |
136 i = p->data; | 134 i = p->data; |
135 // We must get next iqs element now because the current one | |
136 // could be freed. | |
137 p = g_slist_next(p); | |
138 | |
137 if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) || | 139 if ((!i->ts_expire && now_t > i->ts_create + IQS_MAX_TIMEOUT) || |
138 (i->ts_expire && now_t > i->ts_expire)) { | 140 (i->ts_expire && now_t > i->ts_expire)) { |
139 iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT); | 141 iqs_callback(i->id, NULL, IQS_CONTEXT_TIMEOUT); |
140 } | 142 } |
141 } | 143 } |