diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2017-12-22 14:36:05 -0500 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2017-12-22 19:09:52 -0500 |
commit | b3b1b6532890c70987821946f90c22b8021aaaf8 (patch) | |
tree | 1d92de9cfddf5c02a872b48e5bbc5d9e08d54f8d | |
parent | cd95a89282ef61458c3758d70ebfbd91f303033f (diff) |
tools: bpftool: maps: close json array on error paths of show
We can't return from the middle of do_show(), because
json_array will not be closed. Break out of the loop.
Note that the error handling after the loop depends on
errno, so no need to set err.
Fixes: 831a0aafe5c3 ("tools: bpftool: add JSON output for `bpftool map *` commands")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | tools/bpf/bpftool/map.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index e2450c8e88e6..8368b7ea31b5 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c | |||
@@ -523,21 +523,21 @@ static int do_show(int argc, char **argv) | |||
523 | break; | 523 | break; |
524 | p_err("can't get next map: %s%s", strerror(errno), | 524 | p_err("can't get next map: %s%s", strerror(errno), |
525 | errno == EINVAL ? " -- kernel too old?" : ""); | 525 | errno == EINVAL ? " -- kernel too old?" : ""); |
526 | return -1; | 526 | break; |
527 | } | 527 | } |
528 | 528 | ||
529 | fd = bpf_map_get_fd_by_id(id); | 529 | fd = bpf_map_get_fd_by_id(id); |
530 | if (fd < 0) { | 530 | if (fd < 0) { |
531 | p_err("can't get map by id (%u): %s", | 531 | p_err("can't get map by id (%u): %s", |
532 | id, strerror(errno)); | 532 | id, strerror(errno)); |
533 | return -1; | 533 | break; |
534 | } | 534 | } |
535 | 535 | ||
536 | err = bpf_obj_get_info_by_fd(fd, &info, &len); | 536 | err = bpf_obj_get_info_by_fd(fd, &info, &len); |
537 | if (err) { | 537 | if (err) { |
538 | p_err("can't get map info: %s", strerror(errno)); | 538 | p_err("can't get map info: %s", strerror(errno)); |
539 | close(fd); | 539 | close(fd); |
540 | return -1; | 540 | break; |
541 | } | 541 | } |
542 | 542 | ||
543 | if (json_output) | 543 | if (json_output) |