Any prior use of malloc/realloc/free could have messed things up
Any prior use of the memory returned by malloc/realloc could have messed things up here
Look for
- use before alloc
- use after free
- generally getting the size wrong - int *ptr = malloc(10) does NOT allocate space for 10 integers.
Also, your code has the realloc assignment bug
Code:
char **temp = (char **)realloc(Lines.lpLines, sizeof(char **) * Lines.max );
if ( temp != NULL ) {
Lines.lpLines = temp;
} else {
// cannot realloc
// but at least Lines.lpLines points to what we have so far
}
Use a temp pointer to preserve the old pointer, until you know the new one is allocated.
You really should be using new and delete in C++.