Skip to content

Commit 6cf8de8

Browse files
authored
[Bridge Example] Fix dangling pointer when AddDeviceEndpoint failed (#33956)
* Fix dandling pointer when AddDeviceEndpoint failed * Remove code never be excuted
1 parent ab2907b commit 6cf8de8

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

examples/bridge-app/linux/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
278278
}
279279
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
280280
{
281+
gDevices[index] = nullptr;
281282
return -1;
282283
}
283284
// Handle wrap condition

examples/fabric-bridge-app/linux/DeviceManager.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ int DeviceManager::AddDeviceEndpoint(Device * dev, chip::EndpointId parentEndpoi
161161
}
162162
if (err != CHIP_ERROR_ENDPOINT_EXISTS)
163163
{
164+
mDevices[index] = nullptr;
164165
return -1; // Return error as endpoint addition failed due to an error other than endpoint already exists
165166
}
166167
// Increment the endpoint ID and handle wrap condition
@@ -171,6 +172,7 @@ int DeviceManager::AddDeviceEndpoint(Device * dev, chip::EndpointId parentEndpoi
171172
retryCount++;
172173
}
173174
ChipLogError(NotSpecified, "Failed to add dynamic endpoint after %d retries", kMaxRetries);
175+
mDevices[index] = nullptr;
174176
return -1; // Return error as all retries are exhausted
175177
}
176178
index++;

0 commit comments

Comments
 (0)