Add sock hash earlier to avoid crashes.

This commit is contained in:
Roger A. Light
2014-06-23 23:47:48 +01:00
parent 0fc0e13a8f
commit 3577dbf332
6 changed files with 9 additions and 7 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ int mqtt3_bridge_new(struct mosquitto_db *db, struct _mqtt3_bridge *bridge)
/* (possible from persistent db) */
}else{
/* id wasn't found, so generate a new context */
new_context = mqtt3_context_init(-1);
new_context = mqtt3_context_init(db, -1);
if(!new_context){
return MOSQ_ERR_NOMEM;
}
+4 -1
View File
@@ -24,7 +24,7 @@ Contributors:
#include "uthash.h"
struct mosquitto *mqtt3_context_init(int sock)
struct mosquitto *mqtt3_context_init(struct mosquitto_db *db, int sock)
{
struct mosquitto *context;
char address[1024];
@@ -76,6 +76,9 @@ struct mosquitto *mqtt3_context_init(int sock)
context->ssl = NULL;
#endif
if(context->sock != INVALID_SOCKET){
HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(context->sock), context);
}
return context;
}
+1 -1
View File
@@ -381,7 +381,7 @@ int mqtt3_subs_clean_session(struct mosquitto_db *db, struct mosquitto *context,
/* ============================================================
* Context functions
* ============================================================ */
struct mosquitto *mqtt3_context_init(int sock);
struct mosquitto *mqtt3_context_init(struct mosquitto_db *db, int sock);
void mqtt3_context_cleanup(struct mosquitto_db *db, struct mosquitto *context, bool do_free);
void mqtt3_context_disconnect(struct mosquitto_db *db, struct mosquitto *context);
+1 -2
View File
@@ -104,7 +104,7 @@ int mqtt3_socket_accept(struct mosquitto_db *db, int listensock)
return -1;
}
#endif
new_context = mqtt3_context_init(new_sock);
new_context = mqtt3_context_init(db, new_sock);
if(!new_context){
COMPAT_CLOSE(new_sock);
return -1;
@@ -171,7 +171,6 @@ int mqtt3_socket_accept(struct mosquitto_db *db, int listensock)
#endif
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "New connection from %s on port %d.", new_context->address, new_context->listener->port);
HASH_ADD(hh_sock, db->contexts_by_sock, sock, sizeof(new_context->sock), new_context);
return new_sock;
}
+1 -1
View File
@@ -46,7 +46,7 @@ static struct mosquitto *_db_find_or_add_context(struct mosquitto_db *db, const
context = NULL;
HASH_FIND(hh_id, db->contexts_by_id, client_id, strlen(client_id), context);
if(!context){
context = mqtt3_context_init(-1);
context = mqtt3_context_init(db, -1);
if(!context) return NULL;
context->id = _mosquitto_strdup(client_id);
if(!context){
+1 -1
View File
@@ -119,7 +119,7 @@ static int callback_mqtt(struct libwebsocket_context *context,
switch (reason) {
case LWS_CALLBACK_ESTABLISHED:
mosq = mqtt3_context_init(-1);
mosq = mqtt3_context_init(db, -1);
if(mosq){
mosq->ws_context = context;
mosq->wsi = wsi;