attractivechaos / klib

A standalone and lightweight C library
http://attractivechaos.github.io/klib/
MIT License
4.18k stars 556 forks source link

asan detect khash memory issue #136

Closed fr0zenrain closed 4 years ago

fr0zenrain commented 4 years ago

i use this demo compile use fsanitize=address,leak, but it have some error.

include

include

include "khash.h"

KHASH_SET_INIT_STR(str)

int main(int argc, char argv[]) { char s[4096]; // max string length: 4095 characters khash_t(str) h; khint_t k; h = kh_init(str); while (scanf("%s", s) > 0) { int absent; k = kh_put(str, h, s, &absent); if (absent) kh_key(h, k) = strdup(s); // else, the key is not touched; we do nothing } printf("# of distinct words: %d\n", kh_size(h)); // IMPORTANT: free memory allocated by strdup() above for (k = 0; k < kh_end(h); ++k) if (kh_exist(h, k)) free((char*)kh_key(h, k)); kh_destroy(str, h); return 0; }

and i debug found kh_destory free not malloc-ed memory cause error .anybody met this? thanks!

fr0zenrain commented 4 years ago

i'm sorry, my environment is not clean. it's ok