https://github.com/rohanasan/rohanasan
Currently built in C for C/C++, But will surely make binding for other programming languages
16 messages · Page 1 of 1 (latest)
https://github.com/rohanasan/rohanasan
Currently built in C for C/C++, But will surely make binding for other programming languages
There are malloc and strdup calls all over the place. I searched the repo for the keyword "free" and only found 3 mentions, all of which were in license terms comment texts.
;compile -fsanitize=leak ```c
// gcc -fsanitize=leak -o detach detach.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <string.h>
#include <time.h>
sem_t sem;
void *fn (void *arg) {
pthread_detach(pthread_self());
char *a = malloc(1048576UL * 64UL);
memset(a, 'x', 1048576UL * 64UL);
fputs("thread done, waking main\n", stderr);
sem_post(&sem);
return NULL;
}
int main (void) {
sem_init(&sem, 0, 0);
pthread_t th;
pthread_create(&th, NULL, fn, NULL);
sem_wait(&sem);
fputs("main sleeping for 100 ms\n", stderr);
clock_nanosleep(CLOCK_MONOTONIC, 0,
&(struct timespec){0,100000000}, NULL);
}
thread done, waking main
main sleeping for 100 ms
=================================================================
==1==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 67108864 byte(s) in 1 object(s) allocated from:
#0 0x7fa70be7ace5 in malloc (/opt/compiler-explorer/gcc-13.2.0/lib64/liblsan.so.0+0x13ce5) (BuildId: 4db67e889b78df266fcfe97c5c2d3c0155bb7711)
#1 0x4011d8 in fn /app/example.c:13
#2 0x7fa70bc94ac2 (/lib/x86_64-linux-gnu/libc.so.6+0x94ac2) (BuildId: c289da5071a3399de893d2af81d6a30c62646e1e)
SUMMARY: LeakSanitizer: 67108864 byte(s) leaked in 1 allocation(s).
detaching a thread does not prevent memory leaks. you need to free the memory you allocate.
Thanks alot! 😀 I will make the improvements in the code soon 🙂
Every malloc needs to be backed by a free
Yes, my aim is to provide easiness to the programmer using my backend framework. And I will make sure that I free all the memory once it is allocated.
My library can be made even faster and better by doing a better memory handling job 😄 . Thanks everyone!
You could add a more conventional library interface instead of using a compilation stage.
Oh, its like breaking a .h file into a .h and .c files,
.h containing function definitions
.c containing the actual function
?
Declarations in .h, not definitions (the latter is what you call the actual function)
But I also mean a shared library interface. Usually libraries aren't used as source code at all.
Oh! thanks a lot, Ill implement that as well, but will that lead to people typeing:
gcc -o output rohanasan.c main.c
instead of:
gcc ./main.c
?
And, do I need to use extern inline for that? If I want users to compile their C code like this:
gcc ./main.c