From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.raindrops.general Subject: [PATCH] linux_inet_diag: annotate memory freeing on diag errors Date: Sun, 7 Sep 2014 07:12:06 +0000 Message-ID: <20140907071206.GA30143@dcvr.yhbt.net> References: <20140907071206.GA30143@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1410073947 19050 80.91.229.3 (7 Sep 2014 07:12:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Sep 2014 07:12:27 +0000 (UTC) To: raindrops@librelist.org Original-X-From: raindrops@librelist.org Sun Sep 07 09:12:13 2014 Return-path: Envelope-to: gclrrg-raindrops@m.gmane.org In-Reply-To: <20140907071206.GA30143@dcvr.yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: raindrops@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.raindrops.general:144 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XQWdw-0003ee-F1 for gclrrg-raindrops@m.gmane.org; Sun, 07 Sep 2014 09:12:12 +0200 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 3EF3C75027 for ; Sun, 7 Sep 2014 07:25:43 +0000 (UTC) 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