Skip to content

Commit 82a593d

Browse files
committed
fix memory leak
1 parent 1cb49b0 commit 82a593d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/controller/python/chip/clusters/attribute.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -225,27 +225,25 @@ class ReadClientCallback : public ReadClient::Callback
225225

226226
void OnReportEnd() override { gOnReportEndCallback(mAppContext); }
227227

228-
void OnDone(ReadClient *) override
228+
void OnDone(ReadClient * apReadClient) override
229229
{
230230
gOnReadDoneCallback(mAppContext);
231231

232232
// SubscriptionType will delete with pychip_ReadClient_Abort
233-
if (mReadClient->IsReadType())
233+
if (apReadClient->IsReadType())
234234
{
235+
delete apReadClient;
235236
delete this;
236237
}
237238
};
238239

239-
void AdoptReadClient(std::unique_ptr<ReadClient> apReadClient) { mReadClient = std::move(apReadClient); }
240-
241240
void SetAutoResubscribe(bool autoResubscribe) { mAutoResubscribe = autoResubscribe; }
242241

243242
private:
244243
BufferedReadCallback mBufferedReadCallback;
245244

246245
PyObject * mAppContext;
247246

248-
std::unique_ptr<ReadClient> mReadClient;
249247
bool mAutoResubscribe = true;
250248
};
251249

@@ -459,6 +457,7 @@ void pychip_ReadClient_Abort(ReadClient * apReadClient, ReadClientCallback * apC
459457
VerifyOrDie(apReadClient != nullptr);
460458
VerifyOrDie(apCallback != nullptr);
461459

460+
delete apReadClient;
462461
delete apCallback;
463462
}
464463

@@ -609,10 +608,6 @@ PyChipError pychip_ReadClient_Read(void * appContext, ReadClient ** pReadClient,
609608
*pReadClient = readClient.get();
610609
*pCallback = callback.get();
611610

612-
callback->AdoptReadClient(std::move(readClient));
613-
614-
callback.release();
615-
616611
exit:
617612
return ToPyChipError(err);
618613
}

0 commit comments

Comments
 (0)