From 9230d3903f073e867da597491d885af2c6aa3198 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 6 Oct 2023 09:46:01 +0000 Subject: [PATCH] xap_helper.h: strdup keys for DragonFlyBSD hdestroy(3) DragonFlyBSD matches OpenBSD behavior in freeing every single key on hdestroy(3). I suppose hdestroy(3) is neglected enough these days that nobody cares and we'll likely introduce a small C hash table such as khash (also used within git). --- lib/PublicInbox/xap_helper.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h index a78a3f769..3fa615a5f 100644 --- a/lib/PublicInbox/xap_helper.h +++ b/lib/PublicInbox/xap_helper.h @@ -491,11 +491,20 @@ static enum exc_iter dump_roots_iter(struct req *req, static char *hsearch_enter_key(char *s) { -#if defined(__OpenBSD__) /* hdestroy frees each key */ +#if defined(__OpenBSD__) || defined(__DragonFly__) + // hdestroy frees each key on some platforms, + // so give it something to free: char *ret = strdup(s); if (!ret) perror("strdup"); return ret; -#endif // glibc, musl, FreeBSD, NetBSD do not free keys +// AFAIK there's no way to detect musl, assume non-glibc Linux is musl: +#elif defined(__GLIBC__) || defined(__linux__) || \ + defined(__FreeBSD__) || defined(__NetBSD__) + // do nothing on these platforms +#else +#warning untested platform detected, unsure if hdestroy(3) frees keys +#warning contact us at meta@public-inbox.org if you get segfaults +#endif return s; } -- 2.47.3