Fix possible leak during connect.

Closes #2057. Thanks to Przemysław Zygmunt.
pull/2092/head
Roger A. Light 5 years ago
parent 1e6be1f123
commit 7a3b69f2d7

@ -1,6 +1,7 @@
Broker: Broker:
- Fix exporting of executable symbols on BSD when building via makefile. - Fix exporting of executable symbols on BSD when building via makefile.
- Fix some minor memory leaks on exit only. - Fix some minor memory leaks on exit only.
- Fix possible memory leak on connect. Closes #2057.
Clients: Clients:
- Fix config files truncating options after the first space. Closes #2059. - Fix config files truncating options after the first space. Closes #2059.

@ -351,7 +351,6 @@ static int will__read(struct mosquitto *context, const char *client_id, struct m
}else{ }else{
send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL); send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL);
} }
context__disconnect(context);
rc = MOSQ_ERR_PAYLOAD_SIZE; rc = MOSQ_ERR_PAYLOAD_SIZE;
goto error_cleanup; goto error_cleanup;
} }
@ -835,6 +834,7 @@ int handle__connect(struct mosquitto *context)
if(context->auth_method){ if(context->auth_method){
rc = mosquitto_security_auth_start(context, false, auth_data, auth_data_len, &auth_data_out, &auth_data_out_len); rc = mosquitto_security_auth_start(context, false, auth_data, auth_data_len, &auth_data_out, &auth_data_out_len);
mosquitto__free(auth_data); mosquitto__free(auth_data);
auth_data = NULL;
if(rc == MOSQ_ERR_SUCCESS){ if(rc == MOSQ_ERR_SUCCESS){
return connect__on_authorised(context, auth_data_out, auth_data_out_len); return connect__on_authorised(context, auth_data_out, auth_data_out_len);
}else if(rc == MOSQ_ERR_AUTH_CONTINUE){ }else if(rc == MOSQ_ERR_AUTH_CONTINUE){
@ -844,22 +844,23 @@ int handle__connect(struct mosquitto *context)
return rc; return rc;
}else{ }else{
free(auth_data_out); free(auth_data_out);
auth_data_out = NULL;
will__clear(context); will__clear(context);
if(rc == MOSQ_ERR_AUTH){ if(rc == MOSQ_ERR_AUTH){
send__connack(context, 0, MQTT_RC_NOT_AUTHORIZED, NULL); send__connack(context, 0, MQTT_RC_NOT_AUTHORIZED, NULL);
mosquitto__free(context->id); mosquitto__free(context->id);
context->id = NULL; context->id = NULL;
return MOSQ_ERR_PROTOCOL; goto handle_connect_error;
}else if(rc == MOSQ_ERR_NOT_SUPPORTED){ }else if(rc == MOSQ_ERR_NOT_SUPPORTED){
/* Client has requested extended authentication, but we don't support it. */ /* Client has requested extended authentication, but we don't support it. */
send__connack(context, 0, MQTT_RC_BAD_AUTHENTICATION_METHOD, NULL); send__connack(context, 0, MQTT_RC_BAD_AUTHENTICATION_METHOD, NULL);
mosquitto__free(context->id); mosquitto__free(context->id);
context->id = NULL; context->id = NULL;
return MOSQ_ERR_PROTOCOL; goto handle_connect_error;
}else{ }else{
mosquitto__free(context->id); mosquitto__free(context->id);
context->id = NULL; context->id = NULL;
return rc; goto handle_connect_error;
} }
} }
}else{ }else{
@ -885,12 +886,11 @@ int handle__connect(struct mosquitto *context)
}else{ }else{
send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL); send__connack(context, 0, CONNACK_REFUSED_NOT_AUTHORIZED, NULL);
} }
context__disconnect(context);
rc = MOSQ_ERR_AUTH; rc = MOSQ_ERR_AUTH;
goto handle_connect_error; goto handle_connect_error;
break; break;
default: default:
context__disconnect(context); rc = MOSQ_ERR_UNKNOWN;
goto handle_connect_error; goto handle_connect_error;
break; break;
} }

Loading…
Cancel
Save