Categories
Tags
3d ABI Actions algorithms alignment analyze APIT Arc Architecture arm array ascii ash assembly asynchronous attribute base64 bithacks Blogging box c c23 cdylib CHAR_BIT clamp clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete dll doc DP drawio dtruss dylib Dynamic emulator example Example FFI ffmpeg flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative inference intel interop invariant iterator join justfile kernel LaTeX leak LFU limits linux lto MachineLearning macOS map Markdown math ML mmap mod mp3 nc nextest OnceLock optimization OS ownership panic parallels perf physics pin postgresql procedure product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift SIMD sin size SmallProjects so socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous syscall tan test thread time toml tracing traits trap triangulation type uint32_t UnsafeRust utf16 utf8 vector Video vulkan wsl x86_64 xilem zig
226 words
1 minutes
C23_leak_macOS_system_libraries_during_initialization
link
macOS leak 조심하자. 무시해도 되는거구만.
Summary: Your code has no memory leaks. You’re correctly calling
free(s)afterstrdup(). The 120 bytes reported are from macOS system libraries during initialization, which are suppressed with the.lsan.suppfile.The real issue in your output is the typo: “Hello, Worl” - this is because line 8 (
s[n - 1] = 0;) removes the last character ‘d’ since there’s no newline in the original string.
C code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char *s = strdup("Hello, World");
int n = strlen(s);
s[n - 1] = 0;
printf("%s\n", s);
printf("sizeof(*s) = %zu\n", sizeof(*s));
free(s);
return 0;
}.lsan.supp추가해주면 무시해준다
❯ eza -la
.rw-r--r-- 251 gy-gyoung 23 Mar 22:21 .clang-format
.rw-r--r-- 507 gy-gyoung 23 Mar 22:21 .gitignore
.rw-r--r-- 100 gy-gyoung 23 Mar 22:23 .lsan.supp.lsan.supp
# Suppress macOS system library leaks
leak:libobjc.A.dylib
leak:libxpc.dylib
leak:libSystem.B.dylibResult
$ LSAN_OPTIONS=suppressions=../.lsan.supp
rm -rf target
mkdir -p target
/opt/homebrew/opt/llvm/bin/clang -g -fsanitize=leak -fno-omit-frame-pointer -c ./src/main.c
/opt/homebrew/opt/llvm/bin/clang -g -fsanitize=leak *.o
mv a.out *.o ./target
./target/a.out
Hello, Worl
sizeof(*s) = 1
-----------------------------------------------------
Suppressions used:
count bytes template
3 120 libobjc.A.dylib
-----------------------------------------------------C23_leak_macOS_system_libraries_during_initialization
https://younghakim7.github.io/blog/posts/c23_leak_macos_system_libraries_during_initialization/