]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
cherrypick PR33854 fix from main branch
authorSerhei Makarov <serhei@serhei.io>
Thu, 29 Jan 2026 17:27:50 +0000 (12:27 -0500)
committerSerhei Makarov <serhei@serhei.io>
Thu, 5 Feb 2026 15:29:29 +0000 (10:29 -0500)
only difference to draft fix already in branch is in freeing
sample_arg on attach failure

== original commit:

PR33854: fix regression in dwflst_perf_sample_getframes

In commit 3ce0d5ed, I missed the fact that
dwflst_perf_sample_getframes needs to handle the case of an unattached
Dwfl, when dwfl->process->ebl is not yet available to translate the
registers. Thus, it can't be a straightforward wrapper of
dwfl_sample_getframes, but should instead handle the attaching logic
identically to that function.

Also fix a leakage of sample_arg in dwflst_sample_getframes that was
happening on attach failure.

* libdwfl_stacktrace (dwflst_sample_getframes): Fix a leak of
  sample_arg on attach failure.
* libdwfl_stacktrace (dwflst_perf_sample_getframes): Implement
  attaching the Dwfl identically to dwflst_sample_getframes.
  Avoid leaking sample_arg on attach failure.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
libdwfl_stacktrace/dwflst_sample_frame.c

index 9f527579186adf37c6c5eb12568d73f9e6f956cf..cf33a4393321014535c9e9379f1f964a56809993 100644 (file)
@@ -238,7 +238,10 @@ dwflst_sample_getframes (Dwfl *dwfl, Elf *elf,
   if (! attached
       && ! INTUSE(dwfl_attach_state) (dwfl, elf, pid,
                                      &sample_thread_callbacks, sample_arg))
-    return -1;
+    {
+      free(sample_arg);
+      return -1;
+    }
 
   Dwfl_Process *process = dwfl->process;
   Ebl *ebl = process->ebl;
@@ -289,7 +292,10 @@ dwflst_perf_sample_getframes (Dwfl *dwfl, Elf *elf,
   if (! attached
       && ! INTUSE(dwfl_attach_state) (dwfl, elf, pid,
                                      &sample_thread_callbacks, sample_arg))
-    return -1;
+    {
+      free(sample_arg);
+      return -1;
+    }
 
   /* Select the regs_mapping based on architecture.  This will be
      cached in ebl to avoid having to recompute the regs_mapping array