Skip to content

Commit

Permalink
Fix possible leak during connect.
Browse files Browse the repository at this point in the history
Closes #2057. Thanks to Przemysław Zygmunt.
  • Loading branch information
ralight committed Feb 3, 2021
1 parent 1e6be1f commit 7a3b69f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
@@ -1,6 +1,7 @@
Broker:
- Fix exporting of executable symbols on BSD when building via makefile.
- Fix some minor memory leaks on exit only.
- Fix possible memory leak on connect. Closes #2057.

Clients:
- Fix config files truncating options after the first space. Closes #2059.
Expand Down
12 changes: 6 additions & 6 deletions src/handle_connect.c
Expand Up @@ -351,7 +351,6 @@ static int will__read(struct mosquitto *context, const char *client_id, struct m
}else{
send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL);
}
context__disconnect(context);
rc = MOSQ_ERR_PAYLOAD_SIZE;
goto error_cleanup;
}
Expand Down Expand Up @@ -835,6 +834,7 @@ int handle__connect(struct mosquitto *context)
if(context->auth_method){
rc = mosquitto_security_auth_start(context, false, auth_data, auth_data_len, &auth_data_out, &auth_data_out_len);
mosquitto__free(auth_data);
auth_data = NULL;
if(rc == MOSQ_ERR_SUCCESS){
return connect__on_authorised(context, auth_data_out, auth_data_out_len);
}else if(rc == MOSQ_ERR_AUTH_CONTINUE){
Expand All @@ -844,22 +844,23 @@ int handle__connect(struct mosquitto *context)
return rc;
}else{
free(auth_data_out);
auth_data_out = NULL;
will__clear(context);
if(rc == MOSQ_ERR_AUTH){
send__connack(context, 0, MQTT_RC_NOT_AUTHORIZED, NULL);
mosquitto__free(context->id);
context->id = NULL;
return MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
}else if(rc == MOSQ_ERR_NOT_SUPPORTED){
/* Client has requested extended authentication, but we don't support it. */
send__connack(context, 0, MQTT_RC_BAD_AUTHENTICATION_METHOD, NULL);
mosquitto__free(context->id);
context->id = NULL;
return MOSQ_ERR_PROTOCOL;
goto handle_connect_error;
}else{
mosquitto__free(context->id);
context->id = NULL;
return rc;
goto handle_connect_error;
}
}
}else{
Expand All @@ -885,12 +886,11 @@ int handle__connect(struct mosquitto *context)
}else{
send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL);
}
context__disconnect(context);
rc = MOSQ_ERR_AUTH;
goto handle_connect_error;
break;
default:
context__disconnect(context);
rc = MOSQ_ERR_UNKNOWN;
goto handle_connect_error;
break;
}
Expand Down

0 comments on commit 7a3b69f

Please sign in to comment.