my app is use in stlinux (sh4) and unfortunately valgrind does not support sh4 cpu .
since i saw memory leak with my app , i had used mtrace , and it confirmed that some memory is not free . the problem is , variable of malloc used in the return , therefore i do not have any idea , how could i free it (since if it would be free , then returning in the functions is meaningless)
For take a deeper look deeper in entire source code , please check this trac browser :
i had written cs_malloc (put bellow code from oscam-simple.c in above link) , mtrace log says , that in line :
Code:
*tmp = malloc (size);
memory is not free
Code:
/* This function encapsulates malloc. It automatically adds an error message to the log if it failed and calls cs_exit(quiterror) if quiterror > -1.
result will be automatically filled with the new memory position or NULL on failure. */
void *cs_malloc(void *result, size_t size, int32_t quiterror){
void **tmp = result;
*tmp = malloc (size);
if(*tmp == NULL){
cs_log("Couldn't allocate memory (errno=%d %s)!", errno, strerror(errno));
if(quiterror > -1) cs_exit(quiterror);
} else {
memset(*tmp, 0, size);
}
return *tmp;
}
and then for malloc , i call it , like this :
Code:
// create the AES key entry for the linked list
if(!cs_malloc(&new_entry, sizeof(AES_ENTRY), -1)) return;
please take a look at these 3 functions (which malloc is not free , and as other users said , valgrind claim that these codes cause memory leaks cause by these 3 functions module-datastruct-llist.c
the memory leaks cause by 3 different parts :
1. in bellow codes "new" would never free , but since it use in return of that function , i don't have idea , how could i free it
Code:
LL_NODE* ll_append_nolock(LLIST *l, void *obj)
{
if (l && obj) {
LL_NODE *new;
if(!cs_malloc(&new,sizeof(LL_NODE), -1)) return NULL;
new->obj = obj;
if (l->last)
l->last->nxt = new;
else
l->initial = new;
l->last = new;
l->count++;
return new;
}
}
2. also "l" use in bellow function , again since it use in return function , i have no idea how to free it. :
Code:
LLIST *ll_create()
{
LLIST *l = cs_malloc(&l, sizeof(LLIST), 0);
pthread_mutex_init(&l->lock, NULL);
return l;
}
3. same story with new :
Code:
LL_NODE *ll_prepend(LLIST *l, void *obj)
{
if (l && obj) {
LL_NODE *new;
if(!cs_malloc(&new,sizeof(LL_NODE), -1)) return NULL;
new->obj = obj;
ll_lock(l);
new->nxt = l->initial;
l->initial = new;
if (!l->last)
l->last = l->initial;
l->count++;
ll_unlock(l);
return new;
}
return NULL;
}
For more functions u could see module-datastruct-llist.c
Would highly appreciate , if any expert tell me , how could i fix that memory leak (if u feel , cs_malloc should be rewritten , or need to add new fucntion , please write the source code u are meaning.
Thanks in advance