mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* possible memory leak in commands/nand.c?
@ 2009-12-20 19:33 Robert P. J. Day
  2009-12-21  8:45 ` Sascha Hauer
  0 siblings, 1 reply; 4+ messages in thread
From: Robert P. J. Day @ 2009-12-20 19:33 UTC (permalink / raw)
  To: U-Boot Version 2 (barebox)


  once again, perhaps i'm just misreading this but consider this code
from commands/nand.c, noting the two early calls to asprintf():

===== begin =====

        bb = xzalloc(sizeof(*bb));
        bb->devname = asprintf("/dev/%s", basename(path));
        if (name)
                bb->cdev.name = strdup(name);
        else
                bb->cdev.name = asprintf("%s.bb", basename(path));

        ret = stat(bb->devname, &s);
        if (ret)
                goto free_out;

        bb->raw_size = s.st_size;

        bb->fd = open(bb->devname, O_RDWR);
        if (bb->fd < 0) {
                ret = -ENODEV;
                goto free_out;
        }

        ret = ioctl(bb->fd, MEMGETINFO, &bb->info);
        if (ret)
                goto free_out;

        nand_bb_calc_size(bb);
        bb->cdev.ops = &nand_bb_ops;
        bb->cdev.priv = bb;

        devfs_create(&bb->cdev);

        return 0;

free_out:
        free(bb);
        return ret;

===== end =====

  if something in the latter part of that code fails and control jumps
to the label "free_out", won't this code fail to free() the memory
allocated in the two asprintf() calls?  isn't the programmer
explicitly required to free memory allocated with asprintf() or
vasprintf() calls?

rday
--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
========================================================================

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-12-21 10:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-20 19:33 possible memory leak in commands/nand.c? Robert P. J. Day
2009-12-21  8:45 ` Sascha Hauer
2009-12-21  9:17   ` Robert P. J. Day
2009-12-21 10:16     ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox