netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/1] fix: resource leakage when loading library using dlopen
@ 2015-09-07 10:42 Imran Zaman
  2015-09-07 10:41 ` Jan Engelhardt
  0 siblings, 1 reply; 9+ messages in thread
From: Imran Zaman @ 2015-09-07 10:42 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Imran Zaman

dlclose is used to close the handle returned by
dlopen.

Signed-off-by: Imran Zaman <imran.zaman@intel.com>
---
 libxtables/xtables.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index 5357d12..e684d27 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -561,6 +561,7 @@ static void *load_extension(const char *search_path, const char *af_prefix,
 	void *ptr = NULL;
 	struct stat sb;
 	char path[256];
+	void *handle = NULL;
 
 	do {
 		next = strchr(dir, ':');
@@ -579,7 +580,8 @@ static void *load_extension(const char *search_path, const char *af_prefix,
 					strerror(errno));
 				return NULL;
 			}
-			if (dlopen(path, RTLD_NOW) == NULL) {
+			handle = dlopen(path, RTLD_NOW);
+			if (handle == NULL) {
 				fprintf(stderr, "%s: %s\n", path, dlerror());
 				break;
 			}
@@ -590,6 +592,7 @@ static void *load_extension(const char *search_path, const char *af_prefix,
 				ptr = xtables_find_match(name,
 				      XTF_DONT_LOAD, NULL);
 
+			dlclose(handle);
 			if (ptr != NULL)
 				return ptr;
 
-- 
1.9.1

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-09-08 10:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-07 10:42 [PATCH v1 1/1] fix: resource leakage when loading library using dlopen Imran Zaman
2015-09-07 10:41 ` Jan Engelhardt
2015-09-07 10:52   ` Zaman, Imran
2015-09-07 13:08     ` Jan Engelhardt
2015-09-08  7:02       ` Zaman, Imran
2015-09-08  8:55         ` Jan Engelhardt
2015-09-08  9:50           ` Zaman, Imran
2015-09-08 10:05             ` Jan Engelhardt
2015-09-08 10:38           ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).