G
gbostock
I'm working on some legacy code and came across something like this.
Anybody know exactly what the ramifications are to the memory if you do
something like this:
int somefunction (some arguments)
{
....
Mystructtype mystruct;
....
otherfunc(&mystruct); /* this one appears to load up the struct*/
....
free(&mystruct);
func3((void *}&mystruct, sizeof(Mystructtype)); /* func3 takes a void
** and mallocs memory
to set the pointer to point to! */
free(&mystruct);
....
} /* end somefunction */
Now this obviously is really bad, but just what happens? It seems to me
that there is a memory overwrite at the very least or possibly a memory
leak that only lasts as long as the function since the mystruct memory
is automatic anyway.
What would you do about it?
Anybody know exactly what the ramifications are to the memory if you do
something like this:
int somefunction (some arguments)
{
....
Mystructtype mystruct;
....
otherfunc(&mystruct); /* this one appears to load up the struct*/
....
free(&mystruct);
func3((void *}&mystruct, sizeof(Mystructtype)); /* func3 takes a void
** and mallocs memory
to set the pointer to point to! */
free(&mystruct);
....
} /* end somefunction */
Now this obviously is really bad, but just what happens? It seems to me
that there is a memory overwrite at the very least or possibly a memory
leak that only lasts as long as the function since the mystruct memory
is automatic anyway.
What would you do about it?