summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2013-05-21 21:13:50 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-05-21 21:13:51 +0000
commit51a2e4d5d44a6f788da207dff301356e16b4e283 (patch)
tree8149db7af2a1d0ac21814114c6a52baad4250833
parent9246f8d6def40a50933a980fac773a909f2138d7 (diff)
parent544a7f7a36cb9434505fe5cdc9e79d16937ac23f (diff)
downloadcore-51a2e4d5d44a6f788da207dff301356e16b4e283.tar.gz
core-51a2e4d5d44a6f788da207dff301356e16b4e283.tar.bz2
core-51a2e4d5d44a6f788da207dff301356e16b4e283.zip
Merge "libsysutils: fix null pointer and memory leak issue"
-rw-r--r--libsysutils/src/SocketClient.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 3d4984d3b..ae0e0770d 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;
}