Skip to content

Commit f1678ef

Browse files
committed
Disable LD_PRELOAD in subprocesses.
Fixes #19.
1 parent b45164e commit f1678ef

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

filprofiler/_filpreload.c

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static void __attribute__((constructor)) constructor() {
2424
if (initialized) {
2525
return;
2626
}
27+
unsetenv("LD_PRELOAD");
2728
if (sizeof((void *)0) != sizeof((size_t)0)) {
2829
fprintf(stderr, "BUG: expected size of size_t and void* to be the same.\n");
2930
exit(1);

tests/test_endtoend.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""End-to-end tests."""
22

3-
from subprocess import check_call
4-
from tempfile import mkdtemp
3+
from subprocess import check_call, check_output
4+
from tempfile import mkdtemp, NamedTemporaryFile
55
from pathlib import Path
66

77
import pytest
@@ -73,3 +73,19 @@ def test_thread_allocates_after_main_thread_is_done():
7373
script = str(script)
7474
thread1_path1 = (threading, script + ":thread1", ones)
7575
assert allocations[thread1_path1] / 1024 == pytest.approx(70, 0.1)
76+
77+
78+
def test_ld_preload_disabled_for_subprocesses():
79+
"""
80+
LD_PRELOAD is reset so subprocesses don't get the malloc() preload.
81+
"""
82+
with NamedTemporaryFile() as script_file:
83+
script_file.write(
84+
b"""\
85+
import subprocess
86+
print(subprocess.check_output(["env"]))
87+
"""
88+
)
89+
script_file.flush()
90+
result = check_output(["fil-profile", "-o", mkdtemp(), str(script_file.name)])
91+
assert b"LD_PRELOAD" not in result

0 commit comments

Comments
 (0)