coap_session.c: Fix adding NULL pointer on error in coap_new_server_session()

When coap_make_session() fails, the local variable session will be
NULL, and the program continues at the error label. Because of
session == NULL, coap_session_free() will return immediately, leaving
a NULL entry in ep->sessions.

This fix is related to CID 1520613.
This commit is contained in:
Olaf Bergmann authored and obgm committed 2022-08-23 08:43:38 +02:00
1 parent ea89cb842c
commit 5f0eea8dbb
1 file changed
+4 -2
+4 -2
View File
@@ -1383,8 +1383,10 @@ error:
* Need to add in the session as coap_session_release()
* will call SESSIONS_DELETE in coap_session_free().
*/
SESSIONS_ADD(ep->sessions, session);
coap_session_free(session);
if (session) {
SESSIONS_ADD(ep->sessions, session);
coap_session_free(session);
}
return NULL;
}
#endif /* COAP_SERVER_SUPPORT */