[BusyBox] [PATCH] eject umount patch 2

Tito farmatito at tiscali.it
Fri May 13 19:55:22 UTC 2005


On Friday 13 May 2005 16:17, Mike Frysinger wrote:
> On Friday 13 May 2005 08:50 am, Tito wrote:
> >         flags = bb_getopt_ulflags(argc, argv, "t");
> > -
> > -       if (ioctl(bb_xopen((argv[optind] ? argv[optind] : DEFAULT_CDROM),
> > +       
> > +       char *device=argv[optind] ? : DEFAULT_CDROM;
> 
> you need to declare device at the beginning of scope
Done.
> 
> > -
> > -       return EXIT_SUCCESS;
> > +#ifdef CONFIG_FEATURE_CLEAN_UP
> > +       free(command);
> > +       return(EXIT_SUCCESS);
> > +#else
> > +       exit(EXIT_SUCCESS);
> > +#endif
> 
> what's the deal with using return versus exit ?
> -mike

I thought that exit() closes open file descriptors and frees all the memory allocated by the program

Basically the idea was that if we do a free() we don't need an exit()  and could save some space. 

I'm not that sure now as the man pages
speak only about file descriptors........

But: valgrind --tool=memcheck --leak-check=yes --show-reachable=yes  ./test
seems to say that I'm right.
So i'm Just a little confused at the moment.
I can revert it if i'm totally wrong.
I'll wait for some hints from the list before posting patch n°3.

Ciao,
Tito

int main(int argc, char* argv)
{
	char *tmp;
	tmp = malloc(10);
	free(tmp);
	return 0;
} 

==9855== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 14 f
==9855== malloc/free: in use at exit: 0 bytes in 0 blocks.
==9855== malloc/free: 1 allocs, 1 frees, 10 bytes allocated.
==9855== No malloc'd blocks -- no leaks are possible.

int main(int argc, char* argv)
{
	char *tmp;
	tmp = malloc(10);
	exit(0);
} 

==9867== LEAK SUMMARY:
==9867==    definitely lost: 0 bytes in 0 blocks.
==9867==    possibly lost:   0 bytes in 0 blocks.
==9867==    still reachable: 10 bytes in 1 blocks.
==9867==         suppressed: 0 bytes in 0 blocks.

int main(int argc, char* argv)
{
	char *tmp;
	tmp = malloc(10);
	return(0);
} 

==9883== LEAK SUMMARY:
==9883==    definitely lost: 10 bytes in 1 blocks.
==9883==    possibly lost:   0 bytes in 0 blocks.
==9883==    still reachable: 0 bytes in 0 blocks.
==9883==         suppressed: 0 bytes in 0 blocks.



More information about the busybox mailing list