malloc + segmentation fault
Could you help me ?
Code:
//Test part 1
testInt = (strlen(OpenFiles[fileDesc].filename)+1)*sizeof(char);
puts(BBuffer[newBufPos].filename);
//Until here everything works fine
BBuffer[newBufPos].filename = malloc((strlen(OpenFiles[fileDesc].filename)+1)*sizeof(char));
//After malloc i get seg fault but arguments have already check by part 1
puts("********");
if(BBuffer[newBufPos].filename == NULL)
{
BF_errno = BFE_NOMEM;
return BF_errno;
}
The segFault appears at malloc.
At first i thought that might be an accessibility problem (violation access) with (strlen(OpenFiles[fileDesc].filename)+1)*sizeof(char) or BBuffer[newBufPos].filename thats why malloc creates segfault, so i made Test part1 .
Test Part1 works fine !!!!!
I print stars after malloc and they don't appear, this lead me to the conclusion that malloc is the suspect.
Can malloc produce a segmentation fault regardless of my given arguments ?
Should i free filename first ?
Info : Windows XP \ DevC++