Skip to content

Commit a439f41

Browse files
committed
Fix dandling pointer when AddDeviceEndpoint failed
1 parent 8ba371a commit a439f41

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

examples/bridge-app/linux/main.cpp

+3
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
@@ -286,6 +287,8 @@ int AddDeviceEndpoint(Device * dev, EmberAfEndpointType * ep, const Span<const E
286287
gCurrentEndpointId = gFirstDynamicEndpointId;
287288
}
288289
}
290+
// Clear gDevices[index] as all retries are exhausted
291+
gDevices[index] = nullptr;
289292
}
290293
index++;
291294
}

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)