diff options
| author | Colin Cross <ccross@android.com> | 2013-05-21 14:44:36 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2013-05-21 14:44:36 -0700 |
| commit | ea1917f82ef8bd4d8c7b9e69354f89f6bf77195c (patch) | |
| tree | 1525d95f4495c730417244b1f30f5c8a622d06d2 | |
| parent | 4508ef49c00319af7ad0e9630b385b4f786ee959 (diff) | |
| parent | a9e08d3ed60a12f58fc5fdf89f74b4f215ce066f (diff) | |
| download | system_core-ea1917f82ef8bd4d8c7b9e69354f89f6bf77195c.zip system_core-ea1917f82ef8bd4d8c7b9e69354f89f6bf77195c.tar.gz system_core-ea1917f82ef8bd4d8c7b9e69354f89f6bf77195c.tar.bz2 | |
am a9e08d3e: am 51a2e4d5: Merge "libsysutils: fix null pointer and memory leak issue"
* commit 'a9e08d3ed60a12f58fc5fdf89f74b4f215ce066f':
libsysutils: fix null pointer and memory leak issue
| -rw-r--r-- | libsysutils/src/SocketClient.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp index 3d4984d..ae0e077 100644 --- a/libsysutils/src/SocketClient.cpp +++ b/libsysutils/src/SocketClient.cpp @@ -112,6 +112,12 @@ char *SocketClient::quoteArg(const char *arg) { char *result = (char *)malloc(len * 2 + 3); char *current = result; const char *end = arg + len; + char *oldresult; + + if(result == NULL) { + SLOGW("malloc error (%s)", strerror(errno)); + return NULL; + } *(current++) = '"'; while (arg < end) { @@ -125,8 +131,9 @@ char *SocketClient::quoteArg(const char *arg) { } *(current++) = '"'; *(current++) = '\0'; + oldresult = result; // save pointer in case realloc fails result = (char *)realloc(result, current-result); - return result; + return result ? result : oldresult; } |
