Hi all,
I had a bug in my application that I THINK I fixed but I want to propose
my theory and see if it's correct.
What I was doing was this:
1) allocate memory via malloc() for var1 (char*)
2) allocate memory via malloc() for var2 (char*)
3) var1 points to a string "house"
4) var2 = strstr(var1, "s") so now var2 points to the "s" contained in var1
5) free (var1)
6) free (var2)
Step 6 was creating a SIGABRT from free().
My hypothesis:
Since var2 is pointing to var1 I never need to free var2 as long as I free var1,
since it is not a copy, but rather a pointer to the same memory allocated for var1.
Thus, when I free var1, var2's memory is also freed, since they're essentially the
same.
This means I also never need to malloc() for var2, since it will only point to
somewhere within var1, or NULL.
Assuming the above, my app seems to work fine, but I was hoping someone could
verify my thinking or correct it since there might be a bug lurking.
Thanks.