Skip to content

Commit

Permalink
[Bridge Example] Fix dangling pointer when AddDeviceEndpoint failed (#…
Browse files Browse the repository at this point in the history
…33956)

* Fix dandling pointer when AddDeviceEndpoint failed

* Remove code never be excuted
  • Loading branch information
yufengwangca authored and pull[bot] committed Sep 9, 2024
1 parent 516cec3 commit 3ea5720
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/bridge-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
}
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
{
gDevices[index] = nullptr;
return -1;
}
// Handle wrap condition
Expand Down
2 changes: 2 additions & 0 deletions examples/fabric-bridge-app/linux/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ int DeviceManager::AddDeviceEndpoint(Device * dev, chip::EndpointId parentEndpoi
}
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
{
mDevices[index] = nullptr;
return -1; // Return error as endpoint addition failed due to an error other than endpoint already exists
}
// Increment the endpoint ID and handle wrap condition
Expand All @@ -171,6 +172,7 @@ int DeviceManager::AddDeviceEndpoint(Device * dev, chip::EndpointId parentEndpoi
retryCount++;
}
ChipLogError(NotSpecified, "Failed to add dynamic endpoint after %d retries", kMaxRetries);
mDevices[index] = nullptr;
return -1; // Return error as all retries are exhausted
}
index++;
Expand Down

0 comments on commit 3ea5720

Please sign in to comment.