From 93a1aecac406e36076dffe6ee56e28e8be923328 Mon Sep 17 00:00:00 2001 From: Jiung Date: Fri, 13 Oct 2017 14:38:19 +0900 Subject: [PATCH] Fix double free Change-Id: I1f29c37f9a45fb38278b4de2ed0f19b718b1a4e1 Signed-off-by: Yu jiung --- packaging/asp-manager.spec | 2 +- src/session/asp-session-peer.c | 26 +++++++++++++------------- src/session/asp-session.c | 42 +++++++++++++++++++++--------------------- src/session/gfsm.c | 4 +++- src/session/gfsm.h | 4 ++-- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/packaging/asp-manager.spec b/packaging/asp-manager.spec index 0b44c7c..cba5c6b 100755 --- a/packaging/asp-manager.spec +++ b/packaging/asp-manager.spec @@ -1,6 +1,6 @@ Name: asp-manager Summary: ASP(application service platform) manager -Version: 0.0.23 +Version: 0.0.24 Release: 1 Group: Network & Connectivity/Other License: Apache-2.0 diff --git a/src/session/asp-session-peer.c b/src/session/asp-session-peer.c index 607dfbe..dfaba9f 100644 --- a/src/session/asp-session-peer.c +++ b/src/session/asp-session-peer.c @@ -283,12 +283,12 @@ gboolean _asp_sess_peer_send_req(GSocketAddress *p_sock_addr, void *p_msg) p_peer = _asp_sess_peer_create_peer(p_sock_addr); g_assert(p_peer); - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_START, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_START, NULL, NULL)); } if (p_peer && p_peer->context) - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_SEND_REQ, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_SEND_REQ, asp_sess_peer_dup_msg_data(p_msg), g_free)); return TRUE; @@ -303,7 +303,7 @@ gboolean _asp_sess_peer_send_ack(GSocketAddress *p_sock_addr, void *p_msg) if (NULL == p_peer) return FALSE; - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_SEND_ACK, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_SEND_ACK, asp_sess_peer_dup_msg_data(p_msg), g_free)); return TRUE; @@ -318,7 +318,7 @@ gboolean _asp_sess_peer_send_nack(GSocketAddress *p_sock_addr, void *p_msg) if (NULL == p_peer) return FALSE; - gfsm_process_event(p_peer->context, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_SEND_NACK, asp_sess_peer_dup_msg_data(p_msg), g_free)); @@ -341,7 +341,7 @@ gboolean _asp_sess_peer_recv_version(GSocketAddress *p_sock_addr, void *p_msg) ack.seq_num = ((asp_version_s *)p_msg)->seq_num; asp_coordination_protocol_send_msg(p_sock_addr, &ack); - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_START, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_START, NULL, NULL)); } else { asp_ack_s ack; @@ -351,7 +351,7 @@ gboolean _asp_sess_peer_recv_version(GSocketAddress *p_sock_addr, void *p_msg) } if (p_peer && p_peer->context) - gfsm_process_event(p_peer->context, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_RECV_VERSION, asp_sess_peer_dup_msg_data(p_msg), g_free)); @@ -371,7 +371,7 @@ gboolean _asp_sess_peer_recv_req(GSocketAddress *p_sock_addr, void *p_msg) return FALSE; } - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_RECV_REQ, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_RECV_REQ, asp_sess_peer_dup_msg_data(p_msg), g_free)); return TRUE; @@ -391,7 +391,7 @@ gboolean _asp_sess_peer_recv_ack(GSocketAddress *p_sock_addr, void *p_msg) ASP_LOGD("%s _asp_sess_peer_recv_ack, opcode:%d session_id:%d", ROLE, p_header->opcode, p_header->session_id); - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_RECV_ACK, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_RECV_ACK, asp_sess_peer_dup_msg_data(p_msg), g_free)); return TRUE; @@ -406,7 +406,7 @@ gboolean _asp_sess_peer_recv_nack(GSocketAddress *p_sock_addr, void *p_msg) if (NULL == p_peer) return FALSE; - gfsm_process_event(p_peer->context, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_RECV_NACK, asp_sess_peer_dup_msg_data(p_msg), g_free)); @@ -425,11 +425,11 @@ gboolean asp_sess_peer_add_session(GSocketAddress *p_sock_addr, p_peer = _asp_sess_peer_create_peer(p_sock_addr); g_assert(p_peer); - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_START, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_START, NULL, NULL)); } if (p_peer && p_peer->context) - gfsm_process_event(p_peer->context, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_ADD_SESSION, _asp_sess_peer_sess_tree_create_key(session_mac, session_id), g_free)); @@ -451,7 +451,7 @@ gboolean asp_sess_peer_del_session(GSocketAddress *p_sock_addr, return TRUE; /*asp_sess_peer_remove_session(p_peer,session_mac,sessiond_id); */ - gfsm_process_event(p_peer->context, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_DEL_SESSION, _asp_sess_peer_sess_tree_create_key(session_mac, session_id), g_free)); @@ -662,7 +662,7 @@ gboolean _asp_sess_peer_notify_timeout_cb(gpointer p_user_data) p_peer->timer_id = 0; - gfsm_process_event(p_peer->context, gfsm_create_event(ASP_S_PEER_EVENT_TIMEOUT, + gfsm_process_event(&(p_peer->context), gfsm_create_event(ASP_S_PEER_EVENT_TIMEOUT, NULL, NULL)); return FALSE; diff --git a/src/session/asp-session.c b/src/session/asp-session.c index 827a95a..7f00699 100644 --- a/src/session/asp-session.c +++ b/src/session/asp-session.c @@ -575,7 +575,7 @@ gboolean asp_session_connect_session_over_p2p(const guint8 *service_mac, p_connect_session->network_role = network_role; p_connect_session->network_config = network_config; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_CONNECT_SESSION_CALLED, p_connect_session, g_free)); @@ -612,7 +612,7 @@ gboolean asp_session_connect_session_over_infra(const gchar *peer_ip, p_connect_session->network_role = 0; p_connect_session->network_config = 0; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_CONNECT_SESSION_CALLED, p_connect_session, g_free)); @@ -634,7 +634,7 @@ gboolean asp_session_defer_session(guint8 *session_mac, guint32 session_id, memcpy(defer_session_param->deferred_response, deferred_response, MIN(length, ASP_DEFER_RESPONSE_BYTE_MAX)); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_DEFER_SESSION_CALLED, defer_session_param, g_free)); @@ -655,7 +655,7 @@ gboolean asp_session_confirm_session(const guint8 *session_mac, confirmed_param->pin = pin; session->confirmed = confirmed; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_CONFIRM_SESSION_CALLED, confirmed_param, g_free)); @@ -670,7 +670,7 @@ gboolean asp_session_set_session_ready(const guint8 *session_mac, asp_session_s *session = _get_exist_session(session_id, session_mac); g_assert(session); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_SET_SESSION_READY_CALLED, NULL, NULL)); return TRUE; @@ -687,7 +687,7 @@ gboolean asp_session_close_session(guint8 *session_mac, guint32 session_id, guint8 *close_reason = (guint8 *) g_malloc(sizeof(guint8)); *close_reason = (guint8) reason; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_CLOSE_SESSION_CALLED, close_reason, g_free)); return TRUE; @@ -707,7 +707,7 @@ gboolean asp_session_bound_port(guint8 *session_mac, guint32 session_id, bound_port_param->local_port = local_port; bound_port_param->proto = protocol; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_BOUND_PORT_CALLED, bound_port_param, g_free)); return TRUE; @@ -742,7 +742,7 @@ void _p2p_conn_session_request_cb(gint32 error_code, const guint8 *session_mac, p_param->get_pin = get_pin; p_param->pin = pin; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_SESSION_REQUEST_CALLED, p_param, g_free)); } } @@ -759,7 +759,7 @@ void _p2p_conn_session_config_request_cb(gint32 error_code, p_param->get_network_config_pin = get_pin; p_param->network_config_pin = pin; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_SESSION_CONFIG_REQUEST_CALLED, p_param, g_free)); } @@ -776,7 +776,7 @@ void _p2p_conn_connect_status_cb(gint32 error_code, const guint8 *session_mac, p_param->status = status; p_param->length = 0; - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_CONNECT_STATUS_CALLED, p_param, g_free)); } } @@ -796,7 +796,7 @@ void _p2p_conn_ip_assigned_cb(gint32 error_code, const guint8 *session_mac, p_param->length = ip_length; ASP_LOGD("%s %d", p_param->peer_ip_addr, p_param->length); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_IP_ASSIGNED, p_param, g_free)); } } @@ -941,36 +941,36 @@ void asp_session_recv_req(GSocketAddress *sock_addr, gpointer p_msg) _send_ack(sock_addr, p_header->seq_num); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_REQUEST_SESSION_RECEIVED, _asp_session_dup_reqeust_session(p_msg), g_free)); } break; case ASP_OPCODE_ADDED_SESSION: _send_ack(sock_addr, p_header->seq_num); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_ADDED_SESSION_RECEIVED, NULL, NULL)); break; case ASP_OPCODE_REJECTED_SESSION: _send_ack(sock_addr, p_header->seq_num); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_REJECTED_SESSION_RECEIVED, NULL, NULL)); break; case ASP_OPCODE_REMOVE_SESSION: _send_ack(sock_addr, p_header->seq_num); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_REMOVE_SESSION_RECEIVED, &((asp_remove_session_s *)p_msg)->reason, NULL)); break; case ASP_OPCODE_ALLOWED_PORT: _send_ack(sock_addr, p_header->seq_num); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_ALLOWED_PORT_RECEIVED, _asp_session_dup_allowed_session(p_msg), g_free)); break; case ASP_OPCODE_DEFERRED_SESSION: _send_ack(sock_addr, p_header->seq_num); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_DEFERRED_SESSION_RECEIVED, NULL, NULL)); break; @@ -996,7 +996,7 @@ void asp_session_recv_ack(GSocketAddress *sock_addr, guint8 *session_mac, asp_session_s *session = _get_exist_session(session_id, session_mac); g_assert(session); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_ACK_RECEIVED, NULL, NULL)); } @@ -1008,7 +1008,7 @@ void asp_session_recv_nack(GSocketAddress *sock_addr, guint8 *session_mac, asp_session_s *session = _get_exist_session(session_id, session_mac); g_assert(session); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_NACK_RECEIVED, NULL, NULL)); } @@ -1024,7 +1024,7 @@ void asp_session_peer_destroyed(guint8 *session_mac, guint32 session_id) return; } - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_PEER_DESTROYED, NULL, NULL)); } @@ -2027,7 +2027,7 @@ void _state_closed_entry_action(void *p_context_data) asp_sess_peer_del_session(session->sock_addr, session->session_mac, session->session_id); - gfsm_process_event(session->context, + gfsm_process_event(&(session->context), gfsm_create_event(SESSION_EVENT_DELETE_SESSION, NULL, NULL)); } diff --git a/src/session/gfsm.c b/src/session/gfsm.c index 8dd6a1c..3db6e2b 100644 --- a/src/session/gfsm.c +++ b/src/session/gfsm.c @@ -303,8 +303,9 @@ gfsm_s *gfsm_get_fsm_of_context(gfsm_context_s *p_context) return p_context->p_fsm; } -void gfsm_process_event(gfsm_context_s *p_context, gfsm_event_s *p_event) +void gfsm_process_event(gfsm_context_s **pp_context, gfsm_event_s *p_event) { + gfsm_context_s *p_context = *pp_context; gfsm_s *p_fsm; ASP_LOGD("process event"); @@ -338,6 +339,7 @@ void gfsm_process_event(gfsm_context_s *p_context, gfsm_event_s *p_event) p_fsm->log_func("[%s] destroy_context was scheduled\n", p_fsm->p_header); gfsm_destroy_context(p_context); + *pp_context = NULL; } } diff --git a/src/session/gfsm.h b/src/session/gfsm.h index 94af17b..ab9d2b7 100644 --- a/src/session/gfsm.h +++ b/src/session/gfsm.h @@ -136,11 +136,11 @@ void gfsm_destroy_context(gfsm_context_s *p_context); /** * @brief this function process event - * @param [in] p_context a pointer of context + * @param [in] pp_context a pointer of pointer of context * @param [in] p_event a pointer of event that will be processed * @return void */ -void gfsm_process_event(gfsm_context_s *p_context, gfsm_event_s *p_event); +void gfsm_process_event(gfsm_context_s **pp_context, gfsm_event_s *p_event); /** * @brief this function return a current state id -- 2.7.4