2 * sparse/check_frees_argument.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * This script is for finding functions like hcd_buffer_free() which free
12 * their arguments. After running it, add those functions to check_memory.c
19 static struct symbol
*this_func
;
21 static void match_function_def(struct symbol
*sym
)
26 static void print_if_arg(char *name
, struct symbol
*sym
)
32 FOR_EACH_PTR(this_func
->ctype
.base_type
->arguments
, arg
) {
33 arg_name
= (arg
->ident
?arg
->ident
->name
:"-");
34 if (sym
== arg
&& !strcmp(name
, arg_name
))
35 smatch_msg("info: frees argument %d", i
);
37 } END_FOR_EACH_PTR(arg
);
40 static void match_call(struct expression
*expr
)
43 struct expression
*tmp
;
47 fn_name
= get_variable_from_expr(expr
->fn
, NULL
);
48 if (!fn_name
|| strcmp(fn_name
, "kfree"))
51 FOR_EACH_PTR(expr
->args
, tmp
) {
52 tmp
= strip_expr(tmp
);
53 name
= get_variable_from_expr(tmp
, &sym
);
54 print_if_arg(name
, sym
);
56 } END_FOR_EACH_PTR(tmp
);
61 void register_frees_argument(int id
)
64 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
65 add_hook(&match_call
, FUNCTION_CALL_HOOK
);