Browse Source

[process] Hold reference to process during call to step()

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>
tags/v1.20.1
Michael Brown 16 years ago
parent
commit
068ef5f72d
1 changed files with 2 additions and 0 deletions
  1. 2
    0
      src/core/process.c

+ 2
- 0
src/core/process.c View File

@@ -82,9 +82,11 @@ void step ( void ) {
82 82
 	list_for_each_entry ( process, &run_queue, list ) {
83 83
 		list_del ( &process->list );
84 84
 		list_add_tail ( &process->list, &run_queue );
85
+		ref_get ( process->refcnt ); /* Inhibit destruction mid-step */
85 86
 		DBGC2 ( process, "PROCESS %p executing\n", process );
86 87
 		process->step ( process );
87 88
 		DBGC2 ( process, "PROCESS %p finished executing\n", process );
89
+		ref_put ( process->refcnt ); /* Allow destruction */
88 90
 		break;
89 91
 	}
90 92
 }

Loading…
Cancel
Save