Author: ngie
Date: Wed Jan  4 04:50:03 2017
New Revision: 311249
URL: https://svnweb.freebsd.org/changeset/base/311249

Log:
  {strchr,strlen}_basic: don't leak the dlopen'ed handle; close after use
  
  MFC after:    3 days
  Reported by:  Coverity
  CID:          978299, 978300

Modified:
  head/contrib/netbsd-tests/lib/libc/string/t_strchr.c
  head/contrib/netbsd-tests/lib/libc/string/t_strlen.c

Modified: head/contrib/netbsd-tests/lib/libc/string/t_strchr.c
==============================================================================
--- head/contrib/netbsd-tests/lib/libc/string/t_strchr.c        Wed Jan  4 
04:32:00 2017        (r311248)
+++ head/contrib/netbsd-tests/lib/libc/string/t_strchr.c        Wed Jan  4 
04:50:03 2017        (r311249)
@@ -58,6 +58,9 @@ ATF_TC_HEAD(strchr_basic, tc)
 
 ATF_TC_BODY(strchr_basic, tc)
 {
+#ifdef __FreeBSD__
+       void *dl_handle;
+#endif
        unsigned int t, a;
        char *off;
        char buf[32];
@@ -245,8 +248,12 @@ ATF_TC_BODY(strchr_basic, tc)
                "abcdefgh/abcdefgh/",
        };
 
-
+#ifdef __FreeBSD__
+       dl_handle = dlopen(NULL, RTLD_LAZY);
+       strchr_fn = dlsym(dl_handle, "test_strlen");
+#else
        strchr_fn = dlsym(dlopen(0, RTLD_LAZY), "test_strchr");
+#endif
        if (!strchr_fn)
                strchr_fn = strchr;
 
@@ -281,6 +288,9 @@ ATF_TC_BODY(strchr_basic, tc)
                        verify_strchr(buf + a, 0xff, t, a);
                }
        }
+#ifdef __FreeBSD__
+       (void)dlclose(dl_handle);
+#endif
 }
 
 ATF_TP_ADD_TCS(tp)

Modified: head/contrib/netbsd-tests/lib/libc/string/t_strlen.c
==============================================================================
--- head/contrib/netbsd-tests/lib/libc/string/t_strlen.c        Wed Jan  4 
04:32:00 2017        (r311248)
+++ head/contrib/netbsd-tests/lib/libc/string/t_strlen.c        Wed Jan  4 
04:50:03 2017        (r311249)
@@ -40,6 +40,9 @@ ATF_TC_HEAD(strlen_basic, tc)
 
 ATF_TC_BODY(strlen_basic, tc)
 {
+#ifdef __FreeBSD__
+       void *dl_handle;
+#endif
        /* try to trick the compiler */
        size_t (*strlen_fn)(const char *);
 
@@ -107,7 +110,12 @@ ATF_TC_BODY(strlen_basic, tc)
         * During testing it is useful have the rest of the program
         * use a known good version!
         */
+#ifdef __FreeBSD__
+       dl_handle = dlopen(NULL, RTLD_LAZY);
+       strlen_fn = dlsym(dl_handle, "test_strlen");
+#else
        strlen_fn = dlsym(dlopen(NULL, RTLD_LAZY), "test_strlen");
+#endif
        if (!strlen_fn)
                strlen_fn = strlen;
 
@@ -134,6 +142,9 @@ ATF_TC_BODY(strlen_basic, tc)
                        }
                }
        }
+#ifdef __FreeBSD__
+       (void)dlclose(dl_handle);
+#endif
 }
 
 ATF_TC(strlen_huge);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to