Re: Possible mem leak in copy_process()

From: Oleg Nesterov
Date: Thu Apr 17 2008 - 08:57:41 EST


Ugh! I'm not sure I really understand what Coverity says, to the
point I am not sure where it thinks the bug is, but

On 04/16, Jesper Juhl wrote:
>
> At conditional (16): "(p)->pid != 0" taking false path
>
> 1331 if (likely(p->pid)) {
> 1332 add_parent(p);
> 1333 if (unlikely(p->ptrace & PT_PTRACED))
> 1334 __ptrace_link(p, current->parent);
> 1335
> 1336 if (thread_group_leader(p)) {
> 1337 if (clone_flags & CLONE_NEWPID)
> 1338 p->nsproxy->pid_ns->child_reaper = p;
> 1339
> 1340 p->signal->leader_pid = pid;
> 1341 p->signal->tty = current->signal->tty;
> 1342 set_task_pgrp(p, task_pgrp_nr(current));
> 1343 set_task_session(p, task_session_nr(current));
> 1344 attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
> 1345 attach_pid(p, PIDTYPE_SID, task_session(current));
> 1346 list_add_tail_rcu(&p->tasks, &init_task.tasks);
> 1347 __get_cpu_var(process_counts)++;
> 1348 }
> 1349 attach_pid(p, PIDTYPE_PID, pid);
> 1350 nr_threads++;
> 1351 }
> 1352
> 1353 total_forks++;
> 1354 spin_unlock(&current->sighand->siglock);
> 1355 write_unlock_irq(&tasklist_lock);
> 1356 proc_fork_connector(p);
> 1357 cgroup_post_fork(p);
>
> Event leaked_storage: Returned without freeing storage "pid"
> Also see events: [alloc_fn][var_assign][pass_arg]

this looks like a false alarm.

p->pid == pid->numbers[0].nr. If "struct pid *pid" was allocated,
its .nr can't be 0.

IOW, !p->pid means that pid == init_struct_pid, it wasn't allocated
but was passed from the caller.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/