Similar to macro in systemd codebase: add a macro that documents we are
"leaking" a pointer that would otherwise be cleaned up by the cleanup
attribute.
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/264
if (!l)
return -ENOMEM;
+ TAKE_PTR(cmd);
*list = l;
- cmd = NULL;
+
return 0;
}
if (!list)
return -ENOMEM;
- opt = NULL;
+ TAKE_PTR(opt);
config->options = list;
+
return 0;
}
if (!list)
return -ENOMEM;
- alias = NULL;
+ TAKE_PTR(alias);
config->aliases = list;
+
return 0;
}
if (!list)
return -ENOMEM;
- p = NULL;
+ TAKE_PTR(p);
config->blacklists = list;
+
return 0;
}
int kmod_file_load_zlib(struct kmod_file *file)
{
+ _cleanup_free_ unsigned char *p = NULL;
int err = 0;
off_t did = 0, total = 0;
- _cleanup_free_ unsigned char *p = NULL;
gzFile gzf;
int gzfd;
did += r;
}
- file->memory = p;
+ file->memory = TAKE_PTR(p);
file->size = did;
- p = NULL;
gzclose(gzf);
+
return 0;
error:
static int do_init_module(struct kmod_module *mod, unsigned int flags, const char *args)
{
+ _cleanup_free_ const void *stripped = NULL;
struct kmod_elf *elf;
const void *mem;
- _cleanup_free_ const void *stripped = NULL;
off_t size;
int err;
n++;
{
- char *ret = buf;
+ char *ret = TAKE_PTR(buf);
+
ret[i] = '\0';
- buf = NULL;
if (linenum)
*linenum += n;
+
return ret;
}
if (r == NULL)
return NULL;
- cwd = NULL;
+ TAKE_PTR(cwd);
+
r[cwdlen] = '/';
memcpy(&r[cwdlen + 1], p, plen + 1);
#error "Unknown sizeof(size_t)"
#endif
}
+
+#define TAKE_PTR(x) \
+ ({ \
+ typeof(x) x__ = x; \
+ (x) = NULL; \
+ x__; \
+ })