Categories
Tags
3d algorithms alignment analyze APIT Arc Architecture arm ascii assembly asynchronous base64 BitHacks Blogging box c c23 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 doc DP drawio dtruss Dynamic emulator example Example FFI 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 interop invariant iterator join justfile kernel LaTeX leak LFU linux lto MachineLearning macOS map Markdown math ML mmap mod nc OnceLock optimization OS ownership panic parallels perf physics pin postgresql product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift sin size SmallProjects socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous tan thread time toml tracing traits triangulation uint32_t UnsafeRust utf16 utf8 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/