[ofa-general] Re: [PATCH] infiniband-diags: Fix memory leaks on IBERROR and IBPANIC

Jason Gunthorpe jgunthorpe at obsidianresearch.com
Thu Mar 12 15:50:29 PDT 2009


On Thu, Mar 12, 2009 at 11:23:07AM -0700, Ira Weiny wrote:
> > >>>It's not a matter of relying on exit for open fds but rather the
> > >>>allocated memory under the covers of mad_rpc_open_port so no longer
> > >>>can one rely on just exit and this needs to be made explicit.
> > >>
> > >> The OS should reclaim any allocated memory not freed by the app when it exits.
> > >> Is this your concern?
> > >
> > > malloc'd memory ?
> > 
> > Many OSs do but not all. Should we rely on this ? Also, don't other
> > userspace programs attempt to properly cleanup after themselves rather
> > than rely on OS cleanup behavior ?
 
> Strictly speaking I think Hal is right on this one.  I should have
> made the change myself was lazy.

I've never heard of or used an OS that has processes (ie exit) and
didn't reclaim FDs and memory. The closest I've ever used was classic
Windows 3.1 vintage where you had processes, but some GUI resources
could leak if not freed. malloc didn't leak. Heck, even DOS reclaimed
straight malloc'd memory.

POSIX environments reclaim virtually everything on exit, though there
are some APIs for shared memory and some types of non POSIX semaphores
that can linger due to their multi-process nature. But these are rare
and need special handling anyhow..

Certainly attempting to unwind malloc, fds, etc at exit on any sort of
POSIX platform is needless busy work.

When you care about stuff like this is if you are making functions
that don't have the luxury of calling exit/abort/etc, like in the
kernel or in some kind of RTOS environment - but in that situation it
is exit that is forbidden and proper resource clean up and error code
returning is just a consequence of getting rid of exit.

Jason



More information about the general mailing list