Commit e77787adef5cb688c86252a92d4bf34948fa131a

Authored by Perry Werneck
1 parent b88b5d23

Fixing linked list management error when removing st callbacks.

src/include/lib3270.h
... ... @@ -473,7 +473,7 @@
473 473 * @return 0 if suceeds, non zero if fails (sets errno).
474 474 *
475 475 */
476   - LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, void * id);
  476 + LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, const void * id);
477 477  
478 478 LIB3270_EXPORT void lib3270_reset_callbacks(H3270 *hSession);
479 479  
... ...
src/lib3270/connect.c
... ... @@ -50,6 +50,8 @@
50 50  
51 51 int lib3270_reconnect(H3270 *hSession, int seconds)
52 52 {
  53 + debug("%s",__FUNCTION__);
  54 +
53 55 FAIL_IF_ONLINE(hSession);
54 56  
55 57 //
... ...
src/lib3270/host.c
... ... @@ -197,11 +197,22 @@ LIB3270_EXPORT const void * lib3270_register_schange(H3270 *hSession, LIB3270_ST
197 197  
198 198 }
199 199  
200   -LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, void * id)
  200 +LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, const void * id)
201 201 {
202 202 struct lib3270_state_callback *st;
203 203 struct lib3270_state_callback *prev = (struct lib3270_state_callback *) NULL;
204 204  
  205 +#ifdef DEBUG
  206 + {
  207 + debug("Before remove of %p (last=%p):",id,hSession->st.last[tx]);
  208 +
  209 + for (st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next)
  210 + {
  211 + debug("%p",st);
  212 + }
  213 + }
  214 +#endif // DEBUG
  215 +
205 216 for (st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next)
206 217 {
207 218 if (st == (struct lib3270_state_callback *)id)
... ... @@ -221,7 +232,21 @@ LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx,
221 232 else
222 233 hSession->st.callbacks[tx] = (struct lib3270_state_callback *) st->next;
223 234  
224   - lib3270_free(id);
  235 + for(st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next)
  236 + hSession->st.last[tx] = st;
  237 +
  238 + lib3270_free((void *) id);
  239 +
  240 +#ifdef DEBUG
  241 + {
  242 + debug("After Remove of %p (last=%p):",id,hSession->st.last[tx]);
  243 +
  244 + for (st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next)
  245 + {
  246 + debug("%p",st);
  247 + }
  248 + }
  249 +#endif // DEBUG
225 250  
226 251 return 0;
227 252 }
... ...