git/trace2
Derrick Stolee c331d73b3e trace2: remove use of xstrdup()
In the previous change, we removed a use of xsprintf() that caused a
recursive die() loop when failing to allocate memory. The trace2 library is
too low-level to be calling die(), especially because of these recursive
loops that can occur during the die handler.

For full defense in depth, we remove the xstrdup() calls from
trace2/tr2_sysenv.c.

First, in tr2_sysenv_cb(), we need to handle a failed assignment of the
value with a zero-valued return to halt the config parsing loop. Note
that we don't want to use a negative return here or we would imply to
the config system that the config key or value was somehow invalid; such
an output would mask the real issue that the process failed to allocate
memory.

Second, in tr2_sysenv_get(), the method will return NULL when strdup()
returns NULL. This return is indistinguishable from the environment variable
having no value. That means that all callers know how to handle a NULL
response, but no behavior change will occur between the case of no
environment being set and detecting an environment variable exists but we
fail to duplicate it. This seems an appropriate trade-off, as an allocation
failure at this level will likely lead to failure in another system, but at
least the trace2 API will not cause the process to fail early.

Helped-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-08-31 11:08:41 -07:00
..
tr2_cfg.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_cfg.h
tr2_cmd_name.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_cmd_name.h
tr2_ctr.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_ctr.h
tr2_dst.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_dst.h
tr2_sid.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_sid.h
tr2_sysenv.c trace2: remove use of xstrdup() 2026-08-31 11:08:41 -07:00
tr2_sysenv.h
tr2_tbuf.c trace2: tolerate failed timestamp formatting 2026-08-31 11:08:41 -07:00
tr2_tbuf.h
tr2_tgt.h
tr2_tgt_event.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_tgt_normal.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_tgt_perf.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_tls.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_tls.h
tr2_tmr.c banned-die: create header for banning of functions 2026-08-31 11:08:41 -07:00
tr2_tmr.h