Skip to content

Instantly share code, notes, and snippets.

@zorgiepoo
Created March 5, 2014 02:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zorgiepoo/9360013 to your computer and use it in GitHub Desktop.
Save zorgiepoo/9360013 to your computer and use it in GitHub Desktop.
task_for_pid() leak when dev ID signed
// task_for_pid leak
// **IMPORTANT** To reproduce this bug, you have to sign this program with a developer ID -- do not use a self-signed certificate or run as root!
// This code will cause taskgated's memory usage to grow (see activity monitor)
// Link to Xcode project with included info.plist: http://tinyurl.com/kps28av
// Radar 16230826
#include <mach/mach_init.h>
#include <mach/task.h>
#include <mach/mach_port.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Enter a PID as an argument\n");
exit(1);
}
printf("Running in infinite loop.. Check memory usage of taskgated to see if it grows in Activity Monitor\n");
pid_t pid = atoi(argv[1]);
while (1)
{
vm_map_t task;
if (task_for_pid(mach_task_self(), pid, &task) != KERN_SUCCESS)
{
printf("task_for_pid failed... aborting\n");
exit(2);
}
// I've also tried using mach_port_mod_refs and mach_port_destroy to no avail
if (mach_port_deallocate(mach_task_self(), task) != KERN_SUCCESS)
{
printf("mach_port_deallocate failed.. aborting\n");
exit(2);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment