There is no need to free the already-added items, they will be freed alongside the codec context. There is also little point in an error message, as the only reason this can fail is malloc failure.