]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
module: use _cleanup_free and remove useless call to free()
authorLucas De Marchi <lucas.demarchi@intel.com>
Mon, 18 Nov 2013 13:52:53 +0000 (11:52 -0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 18 Nov 2013 13:56:57 +0000 (11:56 -0200)
libkmod/libkmod-module.c

index 3adbb69d6a7b1074df3ca609b5ad465c88914618..2f92e16709ef35d2ac23ea3cae7d7de61d467dfa 100644 (file)
@@ -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;
 }