]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xap_helper.h: strdup keys for DragonFlyBSD hdestroy(3)
authorEric Wong <e@80x24.org>
Fri, 6 Oct 2023 09:46:01 +0000 (09:46 +0000)
committerEric Wong <e@80x24.org>
Fri, 6 Oct 2023 21:06:52 +0000 (21:06 +0000)
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

index a78a3f7690ba29844bd99084d21713deed4b5284..3fa615a5fa074de344c965eb9913c5f4c472e377 100644 (file)
@@ -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;
 }