From e77787adef5cb688c86252a92d4bf34948fa131a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 12 Feb 2019 13:50:57 -0200 Subject: [PATCH] Fixing linked list management error when removing st callbacks. --- src/include/lib3270.h | 2 +- src/lib3270/connect.c | 2 ++ src/lib3270/host.c | 29 +++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/include/lib3270.h b/src/include/lib3270.h index 0f245b0..d706deb 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -473,7 +473,7 @@ * @return 0 if suceeds, non zero if fails (sets errno). * */ - LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, void * id); + LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, const void * id); LIB3270_EXPORT void lib3270_reset_callbacks(H3270 *hSession); diff --git a/src/lib3270/connect.c b/src/lib3270/connect.c index f827352..6cbb375 100644 --- a/src/lib3270/connect.c +++ b/src/lib3270/connect.c @@ -50,6 +50,8 @@ int lib3270_reconnect(H3270 *hSession, int seconds) { + debug("%s",__FUNCTION__); + FAIL_IF_ONLINE(hSession); // diff --git a/src/lib3270/host.c b/src/lib3270/host.c index c834051..35e7bff 100644 --- a/src/lib3270/host.c +++ b/src/lib3270/host.c @@ -197,11 +197,22 @@ LIB3270_EXPORT const void * lib3270_register_schange(H3270 *hSession, LIB3270_ST } -LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, void * id) +LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, const void * id) { struct lib3270_state_callback *st; struct lib3270_state_callback *prev = (struct lib3270_state_callback *) NULL; +#ifdef DEBUG + { + debug("Before remove of %p (last=%p):",id,hSession->st.last[tx]); + + for (st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next) + { + debug("%p",st); + } + } +#endif // DEBUG + for (st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next) { if (st == (struct lib3270_state_callback *)id) @@ -221,7 +232,21 @@ LIB3270_EXPORT int lib3270_unregister_schange(H3270 *hSession, LIB3270_STATE tx, else hSession->st.callbacks[tx] = (struct lib3270_state_callback *) st->next; - lib3270_free(id); + for(st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next) + hSession->st.last[tx] = st; + + lib3270_free((void *) id); + +#ifdef DEBUG + { + debug("After Remove of %p (last=%p):",id,hSession->st.last[tx]); + + for (st = hSession->st.callbacks[tx]; st != (struct lib3270_state_callback *) NULL; st = (struct lib3270_state_callback *) st->next) + { + debug("%p",st); + } + } +#endif // DEBUG return 0; } -- libgit2 0.21.2