diff options
author | Ting-Yuan Huang <laszio@google.com> | 2016-11-15 15:35:16 -0800 |
---|---|---|
committer | Ting-Yuan Huang <laszio@google.com> | 2016-11-15 16:55:50 -0800 |
commit | 09bd41d097b15421a6dd7b547fadbb46928b9150 (patch) | |
tree | 3b13b57300fa27ed1247e5b8f92a22339a0d25ae | |
parent | 847670437bd4b11ad1d32ec65be84f39954b0a6c (diff) | |
download | core-09bd41d097b15421a6dd7b547fadbb46928b9150.tar.gz core-09bd41d097b15421a6dd7b547fadbb46928b9150.tar.bz2 core-09bd41d097b15421a6dd7b547fadbb46928b9150.zip |
init: fix memory leaks
It's possible that node is not freed before return.
Test: make WITH_TIDY=1 mmma system/core/init
Change-Id: I648eea9dda006d2b2239e169785190817ad31352
-rw-r--r-- | init/devices.cpp | 9 | ||||
-rw-r--r-- | init/ueventd.cpp | 15 |
2 files changed, 16 insertions, 8 deletions
diff --git a/init/devices.cpp b/init/devices.cpp index 1a6912f82..ff449c9c5 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -109,13 +109,18 @@ int add_dev_perms(const char *name, const char *attr, return -ENOMEM; node->dp.name = strdup(name); - if (!node->dp.name) + if (!node->dp.name) { + free(node); return -ENOMEM; + } if (attr) { node->dp.attr = strdup(attr); - if (!node->dp.attr) + if (!node->dp.attr) { + free(node->dp.name); + free(node); return -ENOMEM; + } } node->dp.perm = perm; diff --git a/init/ueventd.cpp b/init/ueventd.cpp index e7794ec1d..361b925b8 100644 --- a/init/ueventd.cpp +++ b/init/ueventd.cpp @@ -95,7 +95,6 @@ void set_device_permission(int nargs, char **args) int prefix = 0; int wildcard = 0; char *endptr; - char *tmp = 0; if (nargs == 0) return; @@ -129,14 +128,12 @@ void set_device_permission(int nargs, char **args) perm = strtol(args[1], &endptr, 8); if (!endptr || *endptr != '\0') { LOG(ERROR) << "invalid mode '" << args[1] << "'"; - free(tmp); return; } struct passwd* pwd = getpwnam(args[2]); if (!pwd) { LOG(ERROR) << "invalid uid '" << args[2] << "'"; - free(tmp); return; } uid = pwd->pw_uid; @@ -144,11 +141,17 @@ void set_device_permission(int nargs, char **args) struct group* grp = getgrnam(args[3]); if (!grp) { LOG(ERROR) << "invalid gid '" << args[3] << "'"; - free(tmp); return; } gid = grp->gr_gid; - add_dev_perms(name, attr, perm, uid, gid, prefix, wildcard); - free(tmp); + if (add_dev_perms(name, attr, perm, uid, gid, prefix, wildcard) != 0) { + PLOG(ERROR) << "add_dev_perms(name=" << name << + ", attr=" << attr << + ", perm=" << std::oct << perm << std::dec << + ", uid=" << uid << ", gid=" << gid << + ", prefix=" << prefix << ", wildcard=" << wildcard << + ")"; + return; + } } |