Hi,
I am experiencing a memory allocation error.
I have two systems, the program compiles ok on both these systems.
But, on one of the systems I receive a malloc error. Here is the text of the error:
Code:
threads: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted
Now, I write some pieces of code from my program.
I am creating a thread. This thread is created in the following function.
Code:
// necessary structures, and variable declarations
#define MAX_THREADS 2
static rtl_pthread_t threadIds[MAX_THREADS];
void* thread_function_1(void* s);
signed char serversInit(unsigned short num_servers, unsigned long ec_period_reg, void* svs[]){
int ret;
ret = rtl_pthread_create( &threadIds[0], NULL, thread_function_1, svs[0]);
if (ret != 0) {
printf( "Error creating thread %d\n", (int)threadIds[0] );
return -1;
}
return 0;
}
void* thread_function_1(void* sv){
printf("\n says hello \n");
}
The function "serversInit" is called from another file that passes the arguments to this function. Please notice the fourth argument to the thread creation function. This argument is actually passed on to the thread function i.e. "thread_function_1". I think, there might be problem regarding how I initialize that structure and then pass it on to the "serversInit" function. I write the way I am doing it,
Code:
SERVER* svs[2]; // where SERVER is a structure
svs[0] = (SERVER*)malloc(sizeof(SERVER));
if(svs[0] == NULL){
printf("\n Error Allocating Memory\n");
return;
}
svs[1] = (SERVER*)malloc(sizeof(SERVER));
if(svs[1] == NULL){
printf("\n Error Allocating Memory\n");
return;
}
// calling the "serversInit" function.
serversInit(num_servers, 1000, svs);
Please can you provide some help or inputs in this regard.
Thanks.