Merge pull request #487 from Open-CAS/fix-io-put

Avoid nullptr dereference in ocf_io_put
This commit is contained in:
Robert Baldyga 2021-04-06 14:09:09 +02:00 committed by GitHub
commit 7dcf90ef6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -149,13 +149,17 @@ void ocf_io_get(struct ocf_io *io)
void ocf_io_put(struct ocf_io *io) void ocf_io_put(struct ocf_io *io)
{ {
struct ocf_io_internal *ioi = ocf_io_get_internal(io); struct ocf_io_internal *ioi = ocf_io_get_internal(io);
struct ocf_volume *volume;
if (env_atomic_dec_return(&ioi->meta.ref_count)) if (env_atomic_dec_return(&ioi->meta.ref_count))
return; return;
ocf_refcnt_dec(&ioi->meta.volume->refcnt); /* Hold volume reference to avoid use after free of ioi */
volume = ioi->meta.volume;
ocf_io_allocator_del(&ioi->meta.volume->type->allocator, (void *)ioi); ocf_io_allocator_del(&ioi->meta.volume->type->allocator, (void *)ioi);
ocf_refcnt_dec(&volume->refcnt);
} }
ocf_volume_t ocf_io_get_volume(struct ocf_io *io) ocf_volume_t ocf_io_get_volume(struct ocf_io *io)