aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-07-03 14:44:24 +0800
committerRunxi Yu <me@runxiyu.org>2025-07-03 14:44:24 +0800
commit110a91a829d63424bada343594804ebb04aecfc9 (patch)
tree62aa83c1b60e434a44927fc9c8aff50ebc482e9b
parentgit2d: Reformat C code in Linux style (diff)
downloadforge-110a91a829d63424bada343594804ebb04aecfc9.tar.gz
forge-110a91a829d63424bada343594804ebb04aecfc9.tar.zst
forge-110a91a829d63424bada343594804ebb04aecfc9.zip
git2d: Fix pthread leak by setting the detachable attributeHEADv0.1.54master
Co-authored-by: Test_User <hax@runxiyu.org>
Diffstat (limited to '')
-rw-r--r--git2d/main.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/git2d/main.c b/git2d/main.c
index b4e8e61..9140c1d 100644
--- a/git2d/main.c
+++ b/git2d/main.c
@@ -45,6 +45,14 @@ int main(int argc, char **argv)
listen(sock, 128);
+ pthread_attr_t pthread_attr;
+
+ if (pthread_attr_init(&pthread_attr) != 0)
+ err(1, "pthread_attr_init");
+
+ if (pthread_attr_setdetachstate(&pthread_attr, PTHREAD_CREATE_DETACHED) != 0)
+ err(1, "pthread_attr_setdetachstate");
+
for (;;) {
int *conn = malloc(sizeof(int));
if (conn == NULL) {
@@ -61,7 +69,7 @@ int main(int argc, char **argv)
pthread_t thread;
- if (pthread_create(&thread, NULL, session, (void *)conn) != 0) {
+ if (pthread_create (&thread, &pthread_attr, session, (void *)conn) != 0) {
close(*conn);
free(conn);
warn("pthread_create");