diff options
| author | Mauricio Vásquez <[email protected]> | 2022-01-07 15:26:19 +0000 |
|---|---|---|
| committer | Andrii Nakryiko <[email protected]> | 2022-01-13 01:01:36 +0000 |
| commit | fba60b171a0322830b446dd28170092c47243d39 (patch) | |
| tree | 02b727a151b345636d95b4c39a83947cd9d123db /tools/lib/bpf/hashmap.c | |
| parent | Merge tag 'devprop-5.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git... (diff) | |
| download | kernel-fba60b171a0322830b446dd28170092c47243d39.tar.gz kernel-fba60b171a0322830b446dd28170092c47243d39.zip | |
libbpf: Use IS_ERR_OR_NULL() in hashmap__free()
hashmap__new() uses ERR_PTR() to return an error so it's better to
use IS_ERR_OR_NULL() in order to check the pointer before calling
free(). This will prevent freeing an invalid pointer if somebody calls
hashmap__free() with the result of a failed hashmap__new() call.
Signed-off-by: Mauricio Vásquez <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Acked-by: Song Liu <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/lib/bpf/hashmap.c')
| -rw-r--r-- | tools/lib/bpf/hashmap.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/tools/lib/bpf/hashmap.c b/tools/lib/bpf/hashmap.c index 3c20b126d60d..aeb09c288716 100644 --- a/tools/lib/bpf/hashmap.c +++ b/tools/lib/bpf/hashmap.c @@ -75,7 +75,7 @@ void hashmap__clear(struct hashmap *map) void hashmap__free(struct hashmap *map) { - if (!map) + if (IS_ERR_OR_NULL(map)) return; hashmap__clear(map); @@ -238,4 +238,3 @@ bool hashmap__delete(struct hashmap *map, const void *key, return true; } - |
