sm8450-common: nonui-notifier: Switch to shared_ptr to avoid memory leaks
Change-Id: I950bd5f6abd1dd78093864f5813ab22f0e093ded
This commit is contained in:
@@ -6,7 +6,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <display/drm/mi_disp.h>
|
#include <display/drm/mi_disp.h>
|
||||||
|
|
||||||
bool readBool(int fd);
|
bool readBool(int fd);
|
||||||
disp_event_resp* parseDispEvent(int fd);
|
std::shared_ptr<disp_event_resp> parseDispEvent(int fd);
|
||||||
|
@@ -91,7 +91,7 @@ void AodNotifier::notify() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct disp_event_resp* response = parseDispEvent(disp_fd_.get());
|
std::shared_ptr<disp_event_resp> response = parseDispEvent(disp_fd_.get());
|
||||||
if (response == nullptr) {
|
if (response == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@@ -93,7 +93,7 @@ void LightNotifier::notify() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct disp_event_resp* response = parseDispEvent(disp_fd_.get());
|
std::shared_ptr<disp_event_resp> response = parseDispEvent(disp_fd_.get());
|
||||||
if (response == nullptr) {
|
if (response == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@@ -35,8 +35,8 @@ class NonUiSensorCallback : public IEventQueueCallback {
|
|||||||
|
|
||||||
Return<void> onEvent(const Event& e) {
|
Return<void> onEvent(const Event& e) {
|
||||||
struct touch_mode_request request = {
|
struct touch_mode_request request = {
|
||||||
.mode = TOUCH_MODE_NONUI_MODE,
|
.mode = TOUCH_MODE_NONUI_MODE,
|
||||||
.value = static_cast<int>(e.u.scalar),
|
.value = static_cast<int>(e.u.scalar),
|
||||||
};
|
};
|
||||||
ioctl(touch_fd_.get(), TOUCH_IOC_SET_CUR_VALUE, &request);
|
ioctl(touch_fd_.get(), TOUCH_IOC_SET_CUR_VALUE, &request);
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@ bool readBool(int fd) {
|
|||||||
return c != '0';
|
return c != '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
disp_event_resp* parseDispEvent(int fd) {
|
std::shared_ptr<disp_event_resp> parseDispEvent(int fd) {
|
||||||
disp_event header;
|
disp_event header;
|
||||||
ssize_t headerSize = read(fd, &header, sizeof(header));
|
ssize_t headerSize = read(fd, &header, sizeof(header));
|
||||||
if (headerSize < sizeof(header)) {
|
if (headerSize < sizeof(header)) {
|
||||||
@@ -37,8 +37,12 @@ disp_event_resp* parseDispEvent(int fd) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct disp_event_resp* response =
|
std::shared_ptr<disp_event_resp> response(static_cast<disp_event_resp*>(malloc(header.length)),
|
||||||
reinterpret_cast<struct disp_event_resp*>(malloc(header.length));
|
free);
|
||||||
|
if (!response) {
|
||||||
|
LOG(ERROR) << "failed to allocate memory for display event response";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
response->base = header;
|
response->base = header;
|
||||||
|
|
||||||
int dataLength = response->base.length - sizeof(response->base);
|
int dataLength = response->base.length - sizeof(response->base);
|
||||||
|
Reference in New Issue
Block a user