initArgs must hold a reference on the Root if it is not nil.

The contract in ExecArgs says that a reference on ExecArgs.Root must be held
for the lifetime of the struct, but the caller is free to drop the ref after
that.

As a result, proc.Exec must take an additional ref on Root when it constructs
the CreateProcessArgs, since that holds a pointer to Root as well. That ref is
dropped in CreateProcess.

PiperOrigin-RevId: 212828348
Change-Id: I7f44a612f337ff51a02b873b8a845d3119408707
This commit is contained in:
Nicolas Lacasse
2018-09-13 09:50:35 -07:00
committed by Shentubot
parent d689f8422f
commit e2d79480f5
+5
View File
@@ -132,6 +132,11 @@ func (proc *Proc) execAsync(args *ExecArgs) (*kernel.ThreadGroup, error) {
IPCNamespace: proc.Kernel.RootIPCNamespace(),
AbstractSocketNamespace: proc.Kernel.RootAbstractSocketNamespace(),
}
if initArgs.Root != nil {
// initArgs must hold a reference on Root. This ref is dropped
// in CreateProcess.
initArgs.Root.IncRef()
}
ctx := initArgs.NewContext(proc.Kernel)
if initArgs.Filename == "" {