From: Florian Westphal <fw@strlen.de>
To: Kamil Duljas <kamil.duljas@gmail.com>
Cc: Florian Westphal <fw@strlen.de>, Jakub Kicinski <kuba@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Jiri Pirko <jiri@resnulli.us>,
Johannes Berg <johannes@sipsolutions.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] genetlink: Prevent memory leak when krealloc fail
Date: Sat, 18 Nov 2023 14:42:44 +0100 [thread overview]
Message-ID: <20231118134244.GB30289@breakpoint.cc> (raw)
In-Reply-To: <CAFR=A7nkyx_Lf=p0BS-S68_vxQL97rUoLMZpo4kxHjKykAgTRw@mail.gmail.com>
Kamil Duljas <kamil.duljas@gmail.com> wrote:
> Yes, you're right. I did not think about it. So if we have a static
> pointer that may be resued, should not restore the pointer as at the
> beginning?
> static unsigned long *mc_groups = &mc_group_start;
>
> At this moment we don't know how much memory is allocated. What do you
> think about this?
We do: mc_groups_longs.
> > new_groups = krealloc(mc_groups, nlen,
> > GFP_KERNEL);
> > - if (!new_groups)
> > + if (!new_groups) {
> > + kfree(mc_groups);
> > + mc_groups = &mc_group_start;
> > return -ENOMEM;
> > + }
Seems wrong to shrink when we can't grow. Whats the point?
prev parent reply other threads:[~2023-11-18 13:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-18 11:33 [PATCH] genetlink: Prevent memory leak when krealloc fail Kamil Duljas
2023-11-18 12:02 ` Florian Westphal
2023-11-18 13:27 ` Kamil Duljas
2023-11-18 13:42 ` Florian Westphal [this message]
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=20231118134244.GB30289@breakpoint.cc \
--to=fw@strlen.de \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=johannes@sipsolutions.net \
--cc=kamil.duljas@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).