Closed lukehutch closed 3 years ago
I guess the memory corruption doesn't matter, since the first field of the struct is only overwritten by a type-coerced pointer when the struct is added to the free list. But still, this is pretty ugly, especially when some of the affected structs already have next
fields that could be used...
Closing due to comment on forum about this
This code pattern is used a number of times in
memory.cpp
for memory allocation and recycling (forDevice_t
,Pipe_t
,Transfer_t
, etc.):I don't understand what the intent is here. If
device
has typeDevice_t *
, then*(Device_t **)device
can only make sense if the very first field inDevice_t
is of typeDevice_t *
, i.e. thenext
field. Butnext
is not the first field inDevice_t
. (Same forPipe_t
andTransfer_t
.)I think this usually does not cause a problem for
Memory_t
andPipe_t
, because there is only one of each allocated:However there are 4
Transfer_t
structs allocated:therefore, these methods will corrupt memory, unless I'm misunderstanding the code: