From: Martin Wilck Subject: Re: [PATCH V3] vector: return false if realloc fails in vector_alloc_slot func Date: Wed, 12 Aug 2020 11:20:12 +0200 Message-ID: <33f5dc95064e6d3e9a3bf09f8be40f1b7f6696a0.camel@suse.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: Zhiqiang Liu , Benjamin Marzinski , Christophe Varoqui , Zdenek Kabelac Cc: linfeilong , Yanxiaodan , dm-devel@redhat.com, lixiaokeng List-Id: dm-devel.ids 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 > Signed-off-by: lixiaokeng > Reviewed-by: Martin Wilck