Question about malloc and free
Joel Sherrill
joel.sherrill at oarcorp.com
Wed Nov 14 13:50:40 UTC 2007
Arquer Stephane wrote:
> Hello,
>
> Rtems: 4.7.1
> Bsp: i386-rtems4.7
>
> I've a problem using malloc and free functions, a malloc is used in a
> tool function that return a char* to create a string. The returned
> address is 0x8 which is not a correct one.
>
There is either a bug in the heap code or you have overwritten
a memory buffer allocated from the heap. My hunch is that latter.
Turn on RTEMS_DEBUG and that should enable all the heap
consistency checking.
> Then, a call to free( name_sem ) crash due to
> rtems_region_return_segment(rtems_malloc_heap, ptr); (malloc.c:487)
>
> I'd like to understand why this malloc return such address ?
>
> I use the following code:
> static int posix_bb_sem_get(S_BB_T *bb, int create){
> char* name_sem = NULL;
> int oflag = 0;
> if (create)
> oflag = O_CREAT | O_EXCL;
>
> name_sem = bb_utils_build_sem_name(bb->name);
> bb->priv.posix.sem_id = (sem_t *)sem_open(name_sem, oflag |
> BB_SEM_ACCESS_RIGHT);
>
> if ( bb->priv.posix.sem_id < 0) {
> LOG(BB_LOG_SEVERE, "BlackBoard::bb_create",
> "Cannot create semaphore < %s >", name_sem);
> goto err;
> }
> free(name_sem);
> return BB_NOK;
> }
>
>
>
> Thanks.
>
> sa
>
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users
>
More information about the users
mailing list