From: Davidlohr Bueso <dave@gnu.org>
To: Karel Zak <kzak@redhat.com>
Cc: Petr Uzel <petr.uzel@suse.cz>, util-linux <util-linux@vger.kernel.org>
Subject: Re: [PATCH 5/6] fdisk: introduce fdisk context
Date: Mon, 21 May 2012 12:44:45 +0200 [thread overview]
Message-ID: <1337597085.4538.8.camel@offworld> (raw)
In-Reply-To: <20120521094054.GA14560@x2.net.home>
On Mon, 2012-05-21 at 11:40 +0200, Karel Zak wrote:
> On Sun, May 20, 2012 at 06:11:36PM +0200, Davidlohr Bueso wrote:
> > +struct fdisk_context *fdisk_new_context_from_filename(const char *fname)
> > +{
> > + int fd;
> > + struct fdisk_context *cxt = NULL;
> > +
> > + /*
> > + * Attempt to open the device with r-w permissions
> > + * by default, otherwise try read-only.
> > + */
> > + if ((fd = open(fname, O_RDWR)) < 0)
> > + if ((fd = open(fname, O_RDONLY)) < 0)
> > + goto ret;
>
> return NULL;
>
> > + cxt = calloc(1, sizeof(*cxt));
> > + if (!cxt)
> > + goto ret;
> > +
> > + cxt->dev_fd = fd;
> > + cxt->dev_path = strdup(fname);
> > + if (!cxt->dev_path)
> > + return NULL;
>
> goto fail;
>
> Please, think about it as about library, it meas without memory and
> fd leaks :-)
>
> > +ret:
> > + return cxt;
> > +}
> > +
>
> return cxt;
>
> fail:
> errsv = errno;
Hmm I hadn't considered saving errno stuff...
> fdisk_free_context(cxt);
Yes, we need to plug that descriptor leak! fdisk_free_context() also
frees cxt->dev_path, so we should really just call close(fd).
Thanks,
Davidlohr
> errno = errsv;
> return NULL;
>
>
> Karel
>
next prev parent reply other threads:[~2012-05-21 10:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-20 16:11 [PATCH 5/6] fdisk: introduce fdisk context Davidlohr Bueso
2012-05-21 9:40 ` Karel Zak
2012-05-21 10:44 ` Davidlohr Bueso [this message]
2012-05-21 20:14 ` Davidlohr Bueso
2012-05-21 20:28 ` Davidlohr Bueso
2012-05-23 9:42 ` Karel Zak
2012-05-23 9:51 ` Davidlohr Bueso
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=1337597085.4538.8.camel@offworld \
--to=dave@gnu.org \
--cc=kzak@redhat.com \
--cc=petr.uzel@suse.cz \
--cc=util-linux@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox