Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(i2c_master): NULL pointer dereference in i2c_master_bus_destroy when i2c_master->base is NULL #14845

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions components/esp_driver_i2c/i2c_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,12 @@ static esp_err_t i2c_master_bus_destroy(i2c_master_bus_handle_t bus_handle)
{
ESP_RETURN_ON_FALSE(bus_handle, ESP_ERR_INVALID_ARG, TAG, "no memory for i2c master bus");
i2c_master_bus_handle_t i2c_master = bus_handle;
i2c_common_deinit_pins(i2c_master->base);
if (i2c_release_bus_handle(i2c_master->base) == ESP_OK) {
if (i2c_master) {

// Check if i2c_master->base is not NULL before using it
if (i2c_master->base) {
i2c_common_deinit_pins(i2c_master->base);

if (i2c_release_bus_handle(i2c_master->base) == ESP_OK) {
if (i2c_master->bus_lock_mux) {
vSemaphoreDeleteWithCaps(i2c_master->bus_lock_mux);
i2c_master->bus_lock_mux = NULL;
Expand All @@ -808,16 +811,14 @@ static esp_err_t i2c_master_bus_destroy(i2c_master_bus_handle_t bus_handle)
}
}
bus_handle = NULL;
}

free(i2c_master);
} else {
free(i2c_master);
}
}


free(i2c_master);
return ESP_OK;
}


static esp_err_t s_i2c_asynchronous_transaction(i2c_master_dev_handle_t i2c_dev, i2c_operation_t *i2c_ops, size_t ops_dim, int timeout_ms)
{
i2c_master_bus_t *i2c_master = i2c_dev->master_bus;
Expand Down