changes in v2: 1. add hashtab_destroy_key function in the hashtab.c and declaration in hashtab.h. Replace the original resource release statement with hashtab_destroy_key function. 2. change macro definition to _SELINUX_HASHTAB_H_ in the hashtab.h 3. fix build error: label_file.c:74:77: error: suggest parentheses around arithmetic in operand of ‘|’ [-Werror=parentheses] 74 | (val << 4 | (val >> (8 * sizeof(unsigned int) - 4)) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 75 | k->mode) ^ (*p); | ~~~~~~~ 4. fix memory leak and add oom check in label_file.c 5. fix length parameter of hashtab_create function to hashtab_len 6. move struct chkdups_key to label_file.c v1: https://lore.kernel.org/selinux/20230209114253.120485-1-wanghuizhao1@xxxxxxxxxx/ wanghuizhao (3): libselinux: migrating hashtab from policycoreutils libselinux: adapting hashtab to libselinux libselinux: performance optimization for duplicate detection libselinux/src/hashtab.c | 234 ++++++++++++++++++++++++++++++++++++++++++++ libselinux/src/hashtab.h | 117 ++++++++++++++++++++++ libselinux/src/label_file.c | 118 +++++++++++++++++----- 3 files changed, 445 insertions(+), 24 deletions(-) create mode 100644 libselinux/src/hashtab.c create mode 100644 libselinux/src/hashtab.h -- 2.12.3