diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-12-16 05:45:01 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-12-17 17:11:00 -0500 |
commit | d207cf4c1ad27c6f8881857ca301f8489826116d (patch) | |
tree | 94d8f2b324e5fa4fb04f0714adf569e25a1f226a /tools | |
parent | 8b138da62f3ef370bebaaed7385020993bb787ae (diff) |
bpf_exp: free duplicated labels at exit time
Valgrind found that extracted labels that are passed from the lexer
weren't freed upon exit. Therefore, add a small helper function that
walks label tables and frees them. Since also NULL can be passed to
free(3), we do not need to take care of that here. While at it, fix
up a spacing error in bpf_set_curr_label().
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/net/bpf_exp.y | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/tools/net/bpf_exp.y b/tools/net/bpf_exp.y index f524110643bb..d15efc989ef5 100644 --- a/tools/net/bpf_exp.y +++ b/tools/net/bpf_exp.y | |||
@@ -40,8 +40,8 @@ extern void yyerror(const char *str); | |||
40 | 40 | ||
41 | extern void bpf_asm_compile(FILE *fp, bool cstyle); | 41 | extern void bpf_asm_compile(FILE *fp, bool cstyle); |
42 | static void bpf_set_curr_instr(uint16_t op, uint8_t jt, uint8_t jf, uint32_t k); | 42 | static void bpf_set_curr_instr(uint16_t op, uint8_t jt, uint8_t jf, uint32_t k); |
43 | static void bpf_set_curr_label(const char *label); | 43 | static void bpf_set_curr_label(char *label); |
44 | static void bpf_set_jmp_label(const char *label, enum jmp_type type); | 44 | static void bpf_set_jmp_label(char *label, enum jmp_type type); |
45 | 45 | ||
46 | %} | 46 | %} |
47 | 47 | ||
@@ -573,7 +573,7 @@ txa | |||
573 | 573 | ||
574 | static int curr_instr = 0; | 574 | static int curr_instr = 0; |
575 | static struct sock_filter out[BPF_MAXINSNS]; | 575 | static struct sock_filter out[BPF_MAXINSNS]; |
576 | static const char **labels, **labels_jt, **labels_jf, **labels_k; | 576 | static char **labels, **labels_jt, **labels_jf, **labels_k; |
577 | 577 | ||
578 | static void bpf_assert_max(void) | 578 | static void bpf_assert_max(void) |
579 | { | 579 | { |
@@ -594,13 +594,13 @@ static void bpf_set_curr_instr(uint16_t code, uint8_t jt, uint8_t jf, | |||
594 | curr_instr++; | 594 | curr_instr++; |
595 | } | 595 | } |
596 | 596 | ||
597 | static void bpf_set_curr_label(const char *label) | 597 | static void bpf_set_curr_label(char *label) |
598 | { | 598 | { |
599 | bpf_assert_max(); | 599 | bpf_assert_max(); |
600 | labels[curr_instr] = label; | 600 | labels[curr_instr] = label; |
601 | } | 601 | } |
602 | 602 | ||
603 | static void bpf_set_jmp_label(const char *label, enum jmp_type type) | 603 | static void bpf_set_jmp_label(char *label, enum jmp_type type) |
604 | { | 604 | { |
605 | bpf_assert_max(); | 605 | bpf_assert_max(); |
606 | switch (type) { | 606 | switch (type) { |
@@ -717,12 +717,25 @@ static void bpf_init(void) | |||
717 | assert(labels_k); | 717 | assert(labels_k); |
718 | } | 718 | } |
719 | 719 | ||
720 | static void bpf_destroy_labels(void) | ||
721 | { | ||
722 | int i; | ||
723 | |||
724 | for (i = 0; i < curr_instr; i++) { | ||
725 | free(labels_jf[i]); | ||
726 | free(labels_jt[i]); | ||
727 | free(labels_k[i]); | ||
728 | free(labels[i]); | ||
729 | } | ||
730 | } | ||
731 | |||
720 | static void bpf_destroy(void) | 732 | static void bpf_destroy(void) |
721 | { | 733 | { |
722 | free(labels); | 734 | bpf_destroy_labels(); |
723 | free(labels_jt); | 735 | free(labels_jt); |
724 | free(labels_jf); | 736 | free(labels_jf); |
725 | free(labels_k); | 737 | free(labels_k); |
738 | free(labels); | ||
726 | } | 739 | } |
727 | 740 | ||
728 | void bpf_asm_compile(FILE *fp, bool cstyle) | 741 | void bpf_asm_compile(FILE *fp, bool cstyle) |