fix segfault when getting gvim's cwd

This commit is contained in:
Adrien Schildknecht 2013-05-01 21:53:00 +02:00
parent e414630f01
commit 54c82ee7f7

16
xcwd.c
View File

@ -191,15 +191,21 @@ static int readPath(long pid)
static void cwdOfDeepestChild(processes_t p, long pid) static void cwdOfDeepestChild(processes_t p, long pid)
{ {
int i; int i;
struct proc_s key, *res = NULL, *lastRes; struct proc_s key = {.ppid = pid}, *res = NULL, *lastRes = NULL;
do { do {
lastRes = res; if(res) {
key.ppid = pid; lastRes = res;
key.ppid = res->pid;
}
res = (struct proc_s *)bsearch(&key, p->ps, p->n, res = (struct proc_s *)bsearch(&key, p->ps, p->n,
sizeof(struct proc_s), ppidCmp); sizeof(struct proc_s), ppidCmp);
pid = res ? res->pid : -1; } while(res);
} while(pid != -1);
if(!lastRes) {
readPath(pid);
return;
}
for(i = 0; lastRes != p->ps && (lastRes - i)->ppid == lastRes->ppid; ++i) for(i = 0; lastRes != p->ps && (lastRes - i)->ppid == lastRes->ppid; ++i)
if(readPath((lastRes - i)->pid)) if(readPath((lastRes - i)->pid))