summaryrefslogtreecommitdiff
path: root/tools/incident_report/main.cpp
diff options
context:
space:
mode:
authorYunlian Jiang <yunlian@google.com>2017-07-25 16:03:05 -0700
committerYunlian Jiang <yunlian@google.com>2017-07-25 16:19:19 -0700
commit7a757a0f08eb3b1df8eb7ee2e915682ee4dca555 (patch)
treeca1e2b4e430c9a33ea0843b8106e03b2d405c7b8 /tools/incident_report/main.cpp
parent72376405054e5ba25b9b6e969eb03aa689b2fd16 (diff)
fix a memory leak.
This fixes a memory leak warning: Potential leak of memory pointed to by 'buffer' [clang-analyzer-unix.Malloc] Bug:None Test: The warning is gone. Change-Id: I50bfd9f7d70964da0f1808b73fc6554831020214
Diffstat (limited to 'tools/incident_report/main.cpp')
-rw-r--r--tools/incident_report/main.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/tools/incident_report/main.cpp b/tools/incident_report/main.cpp
index 1d8809f6f603..78e5c054a904 100644
--- a/tools/incident_report/main.cpp
+++ b/tools/incident_report/main.cpp
@@ -297,7 +297,7 @@ static int
adb_incident_workaround(const char* adbSerial, const vector<string>& sections)
{
const int maxAllowedSize = 20 * 1024 * 1024; // 20MB
- uint8_t* buffer = (uint8_t*)malloc(maxAllowedSize);
+ unique_ptr<uint8_t[]> buffer(new uint8_t[maxAllowedSize]);
for (vector<string>::const_iterator it=sections.begin(); it!=sections.end(); it++) {
Descriptor const* descriptor = IncidentProto::descriptor();
@@ -363,7 +363,7 @@ adb_incident_workaround(const char* adbSerial, const vector<string>& sections)
size_t size = 0;
while (size < maxAllowedSize) {
- ssize_t amt = read(pfd[0], buffer + size, maxAllowedSize - size);
+ ssize_t amt = read(pfd[0], buffer.get() + size, maxAllowedSize - size);
if (amt == 0) {
break;
} else if (amt == -1) {
@@ -390,7 +390,7 @@ adb_incident_workaround(const char* adbSerial, const vector<string>& sections)
fprintf(stderr, "write error: %s\n", strerror(err));
return 1;
}
- err = write_all(STDOUT_FILENO, buffer, size);
+ err = write_all(STDOUT_FILENO, buffer.get(), size);
if (err != 0) {
fprintf(stderr, "write error: %s\n", strerror(err));
return 1;
@@ -401,7 +401,6 @@ adb_incident_workaround(const char* adbSerial, const vector<string>& sections)
}
}
- free(buffer);
return 0;
}