about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-11-20 09:14:23 +0000
committerEric Wong <e@80x24.org>2022-12-02 09:40:01 +0000
commit45c7129666ba9e1f82f23f5d6211e0805b04c999 (patch)
treeeda4b5701e50d70443762fd12c5bd87ca6343dc5
parent43ba0b5a8fde89e594d677b5f14946a0cae6d961 (diff)
downloadmwrap-45c7129666ba9e1f82f23f5d6211e0805b04c999.tar.gz
We can also limit the scope of its return value since the
pointers inside the return value do not get freed.
-rw-r--r--mwrap_core.h12
1 files 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();