]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[process] Hold reference to process during call to step()
authorMichael Brown <mcb30@ipxe.org>
Fri, 13 Jun 2008 02:39:22 +0000 (03:39 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 15 Jun 2010 15:26:28 +0000 (16:26 +0100)
It is conceivable that the process may terminate during the execution
of step().  If nothing else holds a reference to the containing
object, this would cause the object to be freed prior to returning
from step().

Add a ref_get()/ref_put() around the call to ->step() to prevent this
from happening.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/process.c

index 940e3b878fe884d2113b31a6900e960c894cae43..d46737b04e908b5877dcfc7eb8f59cf58746f3b8 100644 (file)
@@ -82,9 +82,11 @@ void step ( void ) {
        list_for_each_entry ( process, &run_queue, list ) {
                list_del ( &process->list );
                list_add_tail ( &process->list, &run_queue );
+               ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
                DBGC2 ( process, "PROCESS %p executing\n", process );
                process->step ( process );
                DBGC2 ( process, "PROCESS %p finished executing\n", process );
+               ref_put ( process->refcnt ); /* Allow destruction */
                break;
        }
 }