screencap: fix a memory leak
If fork fails, we'll leak this strdup. The strdup here seems
unnecessary; just use a pointer to the string itself instead.
Caught by the static analyzer:
frameworks/base/cmds/screencap/screencap.cpp:119:8: warning: Potential
leak of memory pointed to by 'fp_arg' [clang-analyzer-unix.Malloc]
Bug: None
Test: TreeHugger
Change-Id: Id7c738ed5c090bcb5b13a6258e91f027ff2b778c
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index 522c272..4410f1c 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -102,14 +102,13 @@
static status_t notifyMediaScanner(const char* fileName) {
std::string filePath("file://");
filePath.append(fileName);
- char* fp_arg = strdup(filePath.c_str());
char *cmd[] = {
(char*) "am",
(char*) "broadcast",
(char*) "am",
(char*) "android.intent.action.MEDIA_SCANNER_SCAN_FILE",
(char*) "-d",
- (char*) fp_arg,
+ &filePath[0],
nullptr
};