diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-11-18 11:52:53 -0200 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-11-18 11:56:57 -0200 |
commit | 9f02561d84235608c3c97ef97e957e331a4c1d82 (patch) | |
tree | a486087bbc1c1d07a46416b946dd2680c719a8a8 | |
parent | d3c16c7946e72b8b88cb41b95dc3d014d24f0e8a (diff) | |
download | kmod-9f02561d84235608c3c97ef97e957e331a4c1d82.tar.gz |
module: use _cleanup_free and remove useless call to free()
-rw-r--r-- | libkmod/libkmod-module.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 3adbb69..2f92e16 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -252,10 +252,8 @@ static int kmod_module_new(struct kmod_ctx *ctx, const char *key, keylen = namelen + aliaslen + 1; m = malloc(sizeof(*m) + (alias == NULL ? 1 : 2) * (keylen + 1)); - if (m == NULL) { - free(m); + if (m == NULL) return -ENOMEM; - } memset(m, 0, sizeof(*m)); @@ -971,7 +969,8 @@ static int module_do_install_commands(struct kmod_module *mod, struct probe_insert_cb *cb) { const char *command = kmod_module_get_install_commands(mod); - char *p, *cmd; + char *p; + _cleanup_free_ char *cmd; int err; size_t cmdlen, options_len, varlen; @@ -994,10 +993,9 @@ static int module_do_install_commands(struct kmod_module *mod, size_t slen = cmdlen - varlen + options_len; char *suffix = p + varlen; char *s = malloc(slen + 1); - if (s == NULL) { - free(cmd); + if (!s) return -ENOMEM; - } + memcpy(s, cmd, p - cmd); memcpy(s + prefixlen, options, options_len); memcpy(s + prefixlen + options_len, suffix, suffixlen); @@ -1013,8 +1011,6 @@ static int module_do_install_commands(struct kmod_module *mod, else err = command_do(mod, "install", cmd); - free(cmd); - return err; } |