mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-22 07:15:14 +03:00
coap_session.c: reference new session objects before release
In case of failure, coap_session_accept() and coap_session_connect()
need to release the session object that has been passed as parameter.
Usually, session->ref would be 0 at the time these functions are
called, causing coap_session_release() to abort in debug mode.
To ensure that the object is referenced at least once,
coap_session_reference() is therefore called before
coap_session_release(). This fixes an error introduced in ommit 46c908a.
This change closes issue #155.
This commit is contained in:
1 parent
a674334afc
commit
f3c1542900
1 file changed
+15
@@ -531,6 +531,11 @@ coap_session_connect(coap_session_t *session) {
|
||||
if (session->tls) {
|
||||
session->state = COAP_SESSION_STATE_HANDSHAKE;
|
||||
} else {
|
||||
/* Need to free session object. As a new session may not yet
|
||||
* have been referenced, we call coap_session_reference() first
|
||||
* before trying to release the object.
|
||||
*/
|
||||
coap_session_reference(session);
|
||||
coap_session_release(session);
|
||||
return NULL;
|
||||
}
|
||||
@@ -547,6 +552,11 @@ coap_session_connect(coap_session_t *session) {
|
||||
coap_session_send_csm(session);
|
||||
}
|
||||
} else {
|
||||
/* Need to free session object. As a new session may not yet
|
||||
* have been referenced, we call coap_session_reference()
|
||||
* first before trying to release the object.
|
||||
*/
|
||||
coap_session_reference(session);
|
||||
coap_session_release(session);
|
||||
return NULL;
|
||||
}
|
||||
@@ -572,6 +582,11 @@ coap_session_accept(coap_session_t *session) {
|
||||
coap_session_send_csm(session);
|
||||
}
|
||||
} else {
|
||||
/* Need to free session object. As a new session may not yet
|
||||
* have been referenced, we call coap_session_reference() first
|
||||
* before trying to release the object.
|
||||
*/
|
||||
coap_session_reference(session);
|
||||
coap_session_release(session);
|
||||
session = NULL;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user