Skip to content

Commit

Permalink
tree-wide: Sprinkle _clang_suppress_alloc_
Browse files Browse the repository at this point in the history
Add the clang::suppress attribute to places where allocation is done and
that rely on the cleanup attribute. Clang analyzer doesn't handle those
(yet), so keep it from giving us false positive.

Signed-off-by: Lucas De Marchi <[email protected]>
  • Loading branch information
lucasdemarchi committed Nov 11, 2024
1 parent 8a28c5a commit 14ef049
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libkmod/libkmod-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static int kmod_config_add_blacklist(struct kmod_config *config, const char *mod

DBG(config->ctx, "modname=%s\n", modname);

p = strdup(modname);
_clang_suppress_alloc_ p = strdup(modname);
if (!p)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion libkmod/libkmod-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ static int module_do_install_commands(struct kmod_module *mod, const char *optio
size_t suffixlen = cmdlen - prefixlen - varlen;
size_t slen = cmdlen - varlen + options_len;
char *suffix = p + varlen;
char *s = malloc(slen + 1);
_clang_suppress_alloc_ char *s = malloc(slen + 1);
if (!s)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion shared/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ int mkdir_p(const char *path, int len, mode_t mode)
_cleanup_free_ char *start;
char *end;

start = memdup(path, len + 1);
_clang_suppress_alloc_ start = memdup(path, len + 1);
if (!start)
return -ENOMEM;

Expand Down
5 changes: 3 additions & 2 deletions tools/depmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods, uint16_
n_r++;
}

stack = malloc(n_r * sizeof(void *));
_clang_suppress_alloc_ stack = malloc(n_r * sizeof(void *));
if (stack == NULL) {
ERR("No memory to report cycles\n");
goto out_list;
Expand Down Expand Up @@ -2920,7 +2920,8 @@ static int do_depmod(int argc, char *argv[])
break;
case 'C': {
size_t bytes = sizeof(char *) * (n_config_paths + 2);
void *tmp = realloc(config_paths, bytes);
_clang_suppress_alloc_ void *tmp = realloc(config_paths, bytes);

if (!tmp) {
fputs("Error: out-of-memory\n", stderr);
goto cmdline_failed;
Expand Down

0 comments on commit 14ef049

Please sign in to comment.