What I (assume) NFITC1 is getting at here is that inputpos offsets such that byte one is element zero, and therefore length = element size * (no of elements + 1). Consider:
Close, but not quite.
size = element_size * (no_of_objects)
Length = no_of_elements
last_index = no_of_elements - 1
last_index = length;
some_operation( data[last_index] );
will always result in memory leaks.
ADDENDUM:
Be advised that the final code block in an LZS file may not be complete. Files rarely fit neatly in this style. So the file might end with
... 12 58 47 69 31 35 77 85
but the final block in the compressed file might be
F9 12 34 50 40 90 85 EOF
Then your control block is still "expecting" four more bytes, but reached the end of the file. You'll have to stop counting once you get to this point.
You might want to change your initial for loop line to
for (int i = 0; i < 8 && inputPos < ll_obj->curr->filesize; i++)Then it'll get kicked out when inputPos = ll_obj->curr->filesize and you'll have reached the end of the compressed file. That will then trigger the while loop condition and kick you out of that too.
PS -
Even though you're not using it now:
int len = (data[inputPos + 1] & 0xF) + 3;
wSize = wSize + len;
Some developers (like me) consider that bad practice to put an arbitrary initializer inside a loop like that. Since len was only used in the line following it's better to just do
wSize = wSize + (data[inputPos + 1] & 0xF) + 3;
then you won't have to guess if you need to clean up len or not. Although this is technically a static data type, good practices on simple things will carry over to larger projects.