All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Donald Yandt <donald.yandt@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH conntrack-tools 1/3] conntrackd: prevent memory loss if reallocation fails
Date: Sat, 2 Mar 2024 10:54:34 +0100	[thread overview]
Message-ID: <ZeL3WvMhrir_Lz-s@calendula> (raw)
In-Reply-To: <20240301170731.21657-2-donald.yandt@gmail.com>



On Fri, Mar 01, 2024 at 12:07:29PM -0500, Donald Yandt wrote:
> Signed-off-by: Donald Yandt <donald.yandt@gmail.com>
> ---
>  src/vector.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/vector.c b/src/vector.c
> index c81e7ce..7f9bc3c 100644
> --- a/src/vector.c
> +++ b/src/vector.c
> @@ -62,11 +62,12 @@ int vector_add(struct vector *v, void *data)
>  {
>  	if (v->cur_elems >= v->max_elems) {
>  		v->max_elems += DEFAULT_VECTOR_GROWTH;
> -		v->data = realloc(v->data, v->max_elems * v->size);
> -		if (v->data == NULL) {

Good catch.

> +		void *ptr = realloc(v->data, v->max_elems * v->size);

Could you declare void *ptr at the top of the function? Following old
style variable declarations?

Thanks.

> +		if (ptr == NULL) {
>  			v->max_elems -= DEFAULT_VECTOR_GROWTH;
>  			return -1;
>  		}
> +		v->data = ptr;
>  	}
>  	memcpy(v->data + (v->size * v->cur_elems), data, v->size);
>  	v->cur_elems++;
> -- 
> 2.44.0
> 
> 

  reply	other threads:[~2024-03-02  9:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 17:07 [PATCH conntrack-tools 0/3] fix potential memory loss and exit codes Donald Yandt
2024-03-01 17:07 ` [PATCH conntrack-tools 1/3] conntrackd: prevent memory loss if reallocation fails Donald Yandt
2024-03-02  9:54   ` Pablo Neira Ayuso [this message]
2024-03-02 16:26     ` Donald Yandt
2024-03-01 17:07 ` [PATCH conntrack-tools 2/3] conntrackd: use size_t for element indices Donald Yandt
2024-03-02  9:53   ` Pablo Neira Ayuso
2024-03-02 16:20     ` Donald Yandt
2024-03-04 12:35       ` Pablo Neira Ayuso
2024-03-01 17:07 ` [PATCH conntrack-tools 3/3] conntrackd: exit with failure status Donald Yandt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZeL3WvMhrir_Lz-s@calendula \
    --to=pablo@netfilter.org \
    --cc=donald.yandt@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.