c
// Document the ownership transfer
/**
 * Remove a stream from the list and transfer ownership to the caller.
 * The caller is responsible for freeing the stream.
 */
jpc_stream_t *jpc_streamlist_remove(jpc_streamlist_t *list, int index);

// When calling the function, the code now knows it owns the stream
tile->pkthdrstream = jpc_streamlist_remove(dec->pkthdrstreams, 0);
if (!tile->pkthdrstream) {
    // Handle error
}

// The code that owns the stream is now responsible for freeing it
jpc_stream_free(tile->pkthdrstream);
