diff --git a/ipc/glue/MessageChannel.cpp b/ipc/glue/MessageChannel.cpp index 83b683aaee3d..1e4e82fe0dd6 100644 --- a/ipc/glue/MessageChannel.cpp +++ b/ipc/glue/MessageChannel.cpp @@ -2073,10 +2073,13 @@ MessageChannel::NotifyMaybeChannelError() return; } + Clear(); + // Oops, error! Let the listener know about it. mChannelState = ChannelError; + + // After this, the channel may be deleted. mListener->OnChannelError(); - Clear(); } void @@ -2228,11 +2231,12 @@ MessageChannel::NotifyChannelClosed() if (ChannelClosed != mChannelState) NS_RUNTIMEABORT("channel should have been closed!"); - // OK, the IO thread just closed the channel normally. Let the - // listener know about it. - mListener->OnChannelClose(); - Clear(); + + // OK, the IO thread just closed the channel normally. Let the + // listener know about it. After this point the channel may be + // deleted. + mListener->OnChannelClose(); } void diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 7eba12e73396..dfaf12b8d2d9 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -3243,6 +3243,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): destroysubtreevar = ExprVar('DestroySubtree') deallocsubtreevar = ExprVar('DeallocSubtree') deallocshmemvar = ExprVar('DeallocShmems') + deallocselfvar = ExprVar('Dealloc' + _actorName(ptype.name(), self.side)) # OnProcesingError(code) codevar = ExprVar('aCode') @@ -3321,7 +3322,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): StmtExpr(ExprCall(destroysubtreevar, args=[ _DestroyReason.NormalShutdown ])), StmtExpr(ExprCall(deallocsubtreevar)), - StmtExpr(ExprCall(deallocshmemvar)) + StmtExpr(ExprCall(deallocshmemvar)), + StmtExpr(ExprCall(deallocselfvar)) ]) else: onclose.addstmt( @@ -3335,7 +3337,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): StmtExpr(ExprCall(destroysubtreevar, args=[ _DestroyReason.AbnormalShutdown ])), StmtExpr(ExprCall(deallocsubtreevar)), - StmtExpr(ExprCall(deallocshmemvar)) + StmtExpr(ExprCall(deallocshmemvar)), + StmtExpr(ExprCall(deallocselfvar)) ]) else: onerror.addstmt( @@ -3557,6 +3560,9 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): ]) self.cls.addstmts([ deallocshmem, Whitespace.NL ]) + deallocself = MethodDefn(MethodDecl(deallocselfvar.name, virtual=1)) + self.cls.addstmts([ deallocself, Whitespace.NL ]) + self.implementPickling() ## private members