#Rohanasan: An extremely fast backend framework

16 messages · Page 1 of 1 (latest)

sage osprey
jade dirge
#

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.

jade dirge
#

;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);
}

dull relicBOT
#
Compiler Output
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).
jade dirge
#

detaching a thread does not prevent memory leaks. you need to free the memory you allocate.

sage osprey
#

Thanks alot! 😀 I will make the improvements in the code soon 🙂

high urchin
#

Every malloc needs to be backed by a free

sage osprey
#

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!

jade dirge
#

You could add a more conventional library interface instead of using a compilation stage.

sage osprey
jade dirge
#

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.

sage osprey
#

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

?

sage osprey
jade dirge
#

You don't need inline in headers if they only have declarations

#

A shared library is only linked with the code that uses it, not compiled with it