c
// Modify jpc_streamlist_remove to return a copy instead of the original
jpc_stream_t *jpc_streamlist_remove_copy(jpc_streamlist_t *list, int idx) {
    jpc_stream_t *original = jpc_streamlist_remove(list, idx);
    if (!original) return NULL;
    jpc_stream_t *copy = jas_stream_clone(original);
    jas_stream_destroy(original);
    return copy;
}

// In the main function:
if (!(tile->pkthdrstream = jpc_streamlist_remove_copy(dec->pkthdrstreams, 0))) {
    return -1;
}
