sval: introduce sval_cmp_t()
[smatch.git] / check_freeing_null.c
blob390336571ed5f8a19e2ad8abad4b02ee7702410d
1 /*
2 * sparse/check_freeing_null.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_free(const char *fn, struct expression *expr, void *data)
16 struct expression *arg_expr;
17 char *name;
18 sval_t sval;
20 arg_expr = get_argument_from_call_expr(expr->args, 0);
21 if (!get_implied_value_sval(arg_expr, &sval))
22 return;
23 if (sval.value != 0)
24 return;
25 name = get_variable_from_expr(arg_expr, NULL);
26 sm_msg("warn: calling %s() when '%s' is always NULL.", fn, name);
27 free_string(name);
30 void check_freeing_null(int id)
32 my_id = id;
33 if (!option_spammy)
34 return;
35 if (option_project == PROJ_KERNEL)
36 add_function_hook("kfree", &match_free, NULL);
37 else
38 add_function_hook("free", &match_free, NULL);