aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZach Shaftel2025-06-11 15:37:31 -0400
committerEli Zaretskii2025-06-14 17:54:06 +0300
commit009cdc8ae09ef060c030feac06578a4ba37cd8c5 (patch)
tree29624799ada8ee27f508fd29a395dd0a0de0f9b6 /src
parente1d0ee1b6b545c82937755dd19787c3d7059eca3 (diff)
downloademacs-009cdc8ae09ef060c030feac06578a4ba37cd8c5.tar.gz
emacs-009cdc8ae09ef060c030feac06578a4ba37cd8c5.zip
Fix segfault in profiler-cpu-log and profiler-memory-log (bug#78763)
* src/profiler.c (export_log): Check if a log has been allocated first, and return nil if it hasn't. (Fprofiler_cpu_log, Fprofiler_memory_log): Doc fix. * test/src/profiler-tests.el (profiler-tests-cpu-profiler) (profiler-tests-memory-profiler): New tests.
Diffstat (limited to 'src')
-rw-r--r--src/profiler.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/profiler.c b/src/profiler.c
index 12d75012c79..f421eb52b31 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -534,7 +534,11 @@ DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log,
534The log is a hash-table mapping backtraces to counters which represent 534The log is a hash-table mapping backtraces to counters which represent
535the amount of time spent at those points. Every backtrace is a vector 535the amount of time spent at those points. Every backtrace is a vector
536of functions, where the last few elements may be nil. 536of functions, where the last few elements may be nil.
537Before returning, a new log is allocated for future samples. */) 537
538If the profiler has not run since the last invocation of
539`profiler-cpu-log' (or was never run at all), return nil. If the
540profiler is currently running, allocate a new log for future samples
541before returning. */)
538 (void) 542 (void)
539{ 543{
540 /* Temporarily stop profiling to avoid it interfering with our data 544 /* Temporarily stop profiling to avoid it interfering with our data
@@ -556,6 +560,7 @@ Before returning, a new log is allocated for future samples. */)
556static Lisp_Object 560static Lisp_Object
557export_log (struct profiler_log *plog) 561export_log (struct profiler_log *plog)
558{ 562{
563 if (!plog->log) return Qnil;
559 log_t *log = plog->log; 564 log_t *log = plog->log;
560 /* The returned hash table uses `equal' as key equivalence predicate 565 /* The returned hash table uses `equal' as key equivalence predicate
561 which is more discriminating than the `function-equal' used by 566 which is more discriminating than the `function-equal' used by
@@ -639,7 +644,11 @@ DEFUN ("profiler-memory-log",
639The log is a hash-table mapping backtraces to counters which represent 644The log is a hash-table mapping backtraces to counters which represent
640the amount of memory allocated at those points. Every backtrace is a vector 645the amount of memory allocated at those points. Every backtrace is a vector
641of functions, where the last few elements may be nil. 646of functions, where the last few elements may be nil.
642Before returning, a new log is allocated for future samples. */) 647
648If the profiler has not run since the last invocation of
649`profiler-memory-log' (or was never run at all), return nil. If the
650profiler is currently running, allocate a new log for future samples
651before returning. */)
643 (void) 652 (void)
644{ 653{
645 bool prof_mem = profiler_memory_running; 654 bool prof_mem = profiler_memory_running;