Description[Mac] Release the mach_host_self() Mach port when done with it.
mach_host_self() and mach_thread_self() return send rights to their
respective Mach ports, which are finite system-wide resources. The port
returned by these calls must be released when the caller finishes using
the port. Failure to do so can exhaust the supply of ports system-wide.
For an example of the type of problem that this can cause, see
http://crbug.com/105513.
I don't believe that PR_GetPhysicalMemorySize is used by Chrome
anywhere, but Chrome does build this code on Mac, and this
mach_host_self() call came up in an audit of un-deallocated ports. This
patch should also be sent upstream.
Note that while you must mach_port_deallocate() the ports you get from
mach_host_self() and mach_thread_self(), you must not normally
deallocate the one from mach_task_self(), because mach_task_self() is
actually just a macro that references a global variable. It doesn’t add
any port rights at all. See <mach/mach_init.h>. If you bypass the macro
and call the real mach_task_self() system call, you do need to call
mach_port_deallocate(), but this situation is incredibly rare.
R=wtc
Patch Set 1 #
Messages
Total messages: 5 (0 generated)
|