raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / Atom feed
* [PATCH] linux_inet_diag: annotate memory freeing on diag errors
@ 2014-09-07  7:12 Eric Wong
  0 siblings, 0 replies; 1+ messages in thread
From: Eric Wong @ 2014-09-07  7:12 UTC (permalink / raw)
  To: raindrops

Clarify the code so memory leak alarms in reviewers eyes do not go off.
---
 ext/raindrops/linux_inet_diag.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c
index e4d0fab..773e094 100644
--- a/ext/raindrops/linux_inet_diag.c
+++ b/ext/raindrops/linux_inet_diag.c
@@ -465,12 +465,12 @@ static VALUE diag(void *ptr)
 		}
 	}
 out:
-	{
+	/* prepare to raise, free memory before reacquiring GVL */
+	if (err && args->table) {
 		int save_errno = errno;
-		if (err && args->table) {
-			st_foreach(args->table, st_free_data, 0);
-			st_free_table(args->table);
-		}
+
+		st_foreach(args->table, st_free_data, 0);
+		st_free_table(args->table);
 		errno = save_errno;
 	}
 	return (VALUE)err;
@@ -584,6 +584,10 @@ static void gen_bytecode(struct iovec *iov, union any_addr *inet)
 	}
 }
 
+/*
+ * n.b. we may safely raise here because an error will cause diag()
+ * to free args->table
+ */
 static void nl_errcheck(VALUE r)
 {
 	const char *err = (const char *)r;
-- 
EW


^ permalink raw reply	[flat|threaded] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-07  7:12 [PATCH] linux_inet_diag: annotate memory freeing on diag errors Eric Wong

raindrops RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/raindrops-public
	git clone --mirror http://ou63pmih66umazou.onion/raindrops-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.raindrops
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.raindrops

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox