[dm-devel] [PATCH V3] vector: return false if realloc fails in vector_alloc_slot func
Martin Wilck
mwilck at suse.com
Wed Aug 12 09:20:12 UTC 2020
On Wed, 2020-08-12 at 16:29 +0800, Zhiqiang Liu wrote:
> In vector_alloc_slot func, if REALLOC fails, it means new slot
> allocation fails. However, it just update v->allocated and then
> return the old v->slot without new slot. So, the caller will take
> the last old slot as the new allocated slot, and use it by calling
> vector_set_slot func. Finally, the data of last slot is lost.
>
> Here, we rewrite vector_alloc_slot as suggested by Martin Wilck:
> - increment v->allocated only after successful allocation,
> - avoid the "if (v->slot)" conditional by just calling realloc(),
> - make sure all newly allocated vector elements are set to NULL,
> - change return value to bool.
>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26 at huawei.com>
> Signed-off-by: lixiaokeng <lixiaokeng at huawei.com>
>
Reviewed-by: Martin Wilck <mwilck at suse.com>
More information about the dm-devel
mailing list