I have a function that takes a string and cuts out a some parts of it.
The function does its thing a couple of times until, all of a sudden, the same malloc line that worked fine, crashes with No source available for "0xb7e88a81" error.
Tried to clear out every thing to make sure I'm not sending NULL length or whatever, but still no luck.
It worked at least once (debugged it) but on the second or third iteration it crashes.
char *removeOffsetFromLabel (char *label) {
char* labelWithoutOffset;
int i;
labelWithoutOffset = malloc(strlen(label));
........
The crash happens on the malloc line (when trying to move to the next line).
strlen(label) = 7 (checked it)
Any ideas ? I'm using GCC compiler on Eclipse (Ubuntu).
Per FoggyDay's request this is the whole function:
char *removeOffsetFromLabel (char *label) {
char* labelWithoutOffset;
int i;
labelWithoutOffset = (char*)malloc(strlen(label) + 1);
i = 0;
while (label[i] != '\0' && label[i] != OPENING_BRACKET_ASCII_CODE) {
labelWithoutOffset[i] = label[i];
i++;
}
labelWithoutOffset[i] = '\0';
return labelWithoutOffset;
}
I do free up "labelWithoutOffset" outside of the function before calling it again.