Skip to content

Commit 18d7b5c

Browse files
committed
fix: use unique_ptr to clean up client
1 parent 6de16ea commit 18d7b5c

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/Capabilities/CameraController.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,23 @@ int CameraController<T>::sendSnapshot(uint8_t* buffer, size_t len) {
8383
int resCode = -1;
8484

8585
#if defined(ESP32)
86-
T *device = static_cast<T *>(this);
87-
88-
// Validate input buffer
86+
T* device = static_cast<T*>(this);
87+
8988
if (!buffer) return resCode;
9089

9190
HTTPClient http;
9291
bool beginSuccess = false;
9392

94-
#ifdef SINRICPRO_NOSSL
95-
WiFiClient *client = new WiFiClient();
96-
if (!client) return resCode;
97-
98-
beginSuccess = http.begin(*client, SINRICPRO_CAMERA_URL, 80, SINRICPRO_CAMERA_PATH, false);
99-
#else
100-
WiFiClientSecure *secureClient = new WiFiClientSecure();
101-
if (!secureClient) return resCode;
102-
103-
secureClient->setInsecure(); // Skip certificate validation
104-
beginSuccess = http.begin(*secureClient, SINRICPRO_CAMERA_URL, 443, SINRICPRO_CAMERA_PATH, true);
105-
#endif
93+
#ifdef SINRICPRO_NOSSL
94+
std::unique_ptr<WiFiClient> client = std::make_unique<WiFiClient>();
95+
if (!client) return resCode;
96+
beginSuccess = http.begin(*client, SINRICPRO_CAMERA_URL, 80, SINRICPRO_CAMERA_PATH, false);
97+
#else
98+
std::unique_ptr<WiFiClientSecure> secureClient = std::make_unique<WiFiClientSecure>();
99+
if (!secureClient) return resCode;
100+
secureClient->setInsecure();
101+
beginSuccess = http.begin(*secureClient, SINRICPRO_CAMERA_URL, 443, SINRICPRO_CAMERA_PATH, true);
102+
#endif
106103

107104
if (!beginSuccess) {
108105
http.end();
@@ -111,7 +108,7 @@ int CameraController<T>::sendSnapshot(uint8_t* buffer, size_t len) {
111108

112109
const String& deviceId = device->getDeviceId();
113110
String createdAt = String(device->getTimestamp());
114-
String signature = device->sign(deviceId+createdAt);
111+
String signature = device->sign(deviceId + createdAt);
115112

116113
http.addHeader(FSTR_SINRICPRO_deviceId, deviceId);
117114
http.addHeader(FSTR_SINRICPRO_createdAt, createdAt);
@@ -120,8 +117,9 @@ int CameraController<T>::sendSnapshot(uint8_t* buffer, size_t len) {
120117
resCode = http.POST(buffer, len);
121118
http.end();
122119
#endif
123-
120+
124121
return resCode;
125122
}
126123

124+
127125
} // namespace SINRICPRO_NAMESPACE

0 commit comments

Comments
 (0)