From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0EE3A1FAF0 for ; Sun, 20 Nov 2022 09:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1668935665; bh=PCCrIqnT5dUx4JoO7LIWSI08WbADPea6mai366iMG5o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=q5r5nZCdjEBTzcxBxanq4zpMdTizK6fJ1thh+AmJunu9sEiErGAm9jX6gLST2YXD1 oKdEoxrWwXYUHeqFVDVBNGqVlFlV6JNvumNAMWGnNz/bzRlNLLmGaadJakC2RRey5+ IBG4WJQfKKj3WNaptl+QaP3z2VCnFGsHdrY4Wy+Q= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 2/3] dump_to_file: check for backtrace_symbols errors Date: Sun, 20 Nov 2022 09:14:23 +0000 Message-Id: <20221120091424.2420768-3-e@80x24.org> In-Reply-To: <20221120091424.2420768-1-e@80x24.org> References: <20221120091424.2420768-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can also limit the scope of its return value since the pointers inside the return value do not get freed. --- mwrap_core.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mwrap_core.h b/mwrap_core.h index 291a078..f3b25b7 100644 --- a/mwrap_core.h +++ b/mwrap_core.h @@ -624,16 +624,20 @@ static void *dump_to_file(struct dump_arg *a) goto out_unlock; cds_lfht_for_each_entry(t, &iter, l, hnode) { const void *p = l->k; - char **s = 0; if (l->total <= a->min) continue; if (loc_is_addr(l)) { - s = backtrace_symbols(p, 1); - p = s[0]; + char **s = backtrace_symbols(p, 1); + if (s) { + p = s[0]; + free(s); + } else { + fprintf(stderr, "backtrace_symbols: %s\n", + strerror(errno)); + } } fprintf(a->fp, "%16zu %12zu %s\n", l->total, l->allocations, (const char *)p); - if (s) free(s); } out_unlock: rcu_read_unlock();