db: move return_values to use raw SQL
[smatch.git] / check_freeing_null.c
blob511806212b20709d3c634096203778697ad35285
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(arg_expr, &sval))
22 return;
23 if (sval.value != 0)
24 return;
25 name = expr_to_var(arg_expr);
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);