@@ -3304,7 +3304,7 @@ public void perform(TimerEvent e){
3304
3304
3305
3305
private volatile String last_bind_fail = null ;
3306
3306
3307
- private boolean destroyed ;
3307
+ private volatile boolean destroyed ;
3308
3308
3309
3309
private
3310
3310
ChatInstance (
@@ -3440,9 +3440,14 @@ public void perform(TimerEvent e){
3440
3440
3441
3441
protected void
3442
3442
addReference ()
3443
- {
3443
+ {
3444
3444
synchronized ( chat_lock ){
3445
3445
3446
+ if ( isDestroyed ()){
3447
+
3448
+ Debug .out ( "Adding reference to a destroyed chat..." );
3449
+ }
3450
+
3446
3451
if ( virtual_reference_count > 0 ){
3447
3452
3448
3453
virtual_reference_count --;
@@ -6480,7 +6485,7 @@ public void perform(TimerEvent event) {
6480
6485
6481
6486
public boolean
6482
6487
isDestroyed ()
6483
- {
6488
+ {
6484
6489
return ( destroyed );
6485
6490
}
6486
6491
@@ -6494,6 +6499,8 @@ public void perform(TimerEvent event) {
6494
6499
destroy (
6495
6500
boolean force )
6496
6501
{
6502
+ boolean do_destroy ;
6503
+
6497
6504
synchronized ( chat_lock ){
6498
6505
6499
6506
if ( force ){
@@ -6513,86 +6520,94 @@ public void perform(TimerEvent event) {
6513
6520
return ;
6514
6521
}
6515
6522
}
6516
- }
6517
-
6518
- if ( !( keep_alive || (have_interest && !is_private_chat ))){
6523
+
6524
+ if ( !( keep_alive || (have_interest && !is_private_chat ))){
6519
6525
6520
- if ( !destroyed ) {
6526
+ do_destroy = !destroyed ;
6521
6527
6522
- destroyed = true ;
6523
-
6524
- for ( ChatListener l : listeners ){
6528
+ if ( do_destroy ){
6529
+
6530
+ destroyed = true ;
6531
+ }
6532
+ }else {
6533
+
6534
+ do_destroy = false ;
6535
+ }
6536
+ }
6525
6537
6526
- try {
6527
- l .stateChanged ( false );
6538
+ if ( do_destroy ){
6539
+
6540
+ for ( ChatListener l : listeners ){
6528
6541
6529
- }catch ( Throwable e ){
6542
+ try {
6543
+ l .stateChanged ( false );
6530
6544
6531
- Debug .out ( e );
6532
- }
6545
+ }catch ( Throwable e ){
6546
+
6547
+ Debug .out ( e );
6533
6548
}
6534
-
6535
- try {
6536
- if ( handler != null ){
6537
-
6538
- if ( is_private_chat ){
6539
-
6540
- Map <String ,Object > flags = new HashMap <>();
6541
-
6542
- flags .put ( FLAGS_MSG_STATUS_KEY , FLAGS_MSG_STATUS_CHAT_QUIT );
6543
-
6544
- sendMessageSupport ( "" , flags , new HashMap <String , Object >());
6545
- }
6546
-
6547
- Map <String ,Object > options = new HashMap <>();
6549
+ }
6550
+
6551
+ try {
6552
+ if ( handler != null ){
6548
6553
6549
- options .put ( "handler" , handler );
6550
-
6551
- Map <String ,Object > reply = (Map <String ,Object >)msgsync_pi .getIPC ().invoke ( "removeMessageHandler" , new Object []{ options } );
6552
- }
6553
- }catch ( Throwable e ){
6554
+ if ( is_private_chat ){
6554
6555
6555
- Debug . out ( e );
6556
+ Map < String , Object > flags = new HashMap <>( );
6556
6557
6557
- }finally {
6558
+ flags .put ( FLAGS_MSG_STATUS_KEY , FLAGS_MSG_STATUS_CHAT_QUIT );
6559
+
6560
+ sendMessageSupport ( "" , flags , new HashMap <String , Object >());
6561
+ }
6562
+
6563
+ Map <String ,Object > options = new HashMap <>();
6564
+
6565
+ options .put ( "handler" , handler );
6558
6566
6559
- String meta_key = network + ":" + key ;
6567
+ Map <String ,Object > reply = (Map <String ,Object >)msgsync_pi .getIPC ().invoke ( "removeMessageHandler" , new Object []{ options } );
6568
+ }
6569
+ }catch ( Throwable e ){
6570
+
6571
+ Debug .out ( e );
6560
6572
6561
- ChatInstance removed = null ;
6573
+ } finally {
6562
6574
6563
- synchronized ( chat_instances_map ){
6575
+ String meta_key = network + ":" + key ;
6564
6576
6565
- ChatInstance inst = chat_instances_map . remove ( meta_key ) ;
6577
+ ChatInstance removed = null ;
6566
6578
6567
- if ( inst != null ){
6579
+ synchronized ( chat_instances_map ){
6568
6580
6569
- removed = inst ;
6581
+ ChatInstance inst = chat_instances_map . remove ( meta_key ) ;
6570
6582
6571
- chat_instances_list .remove ( inst );
6572
- }
6583
+ if ( inst != null ){
6573
6584
6574
- if ( chat_instances_map . size () == 0 ){
6585
+ removed = inst ;
6575
6586
6576
- if ( timer != null ){
6587
+ chat_instances_list .remove ( inst );
6588
+ }
6577
6589
6578
- timer . cancel ();
6590
+ if ( chat_instances_map . size () == 0 ){
6579
6591
6580
- timer = null ;
6581
- }
6592
+ if ( timer != null ){
6593
+
6594
+ timer .cancel ();
6595
+
6596
+ timer = null ;
6582
6597
}
6583
6598
}
6599
+ }
6584
6600
6585
- if ( removed != null ){
6601
+ if ( removed != null ){
6586
6602
6587
- for ( ChatManagerListener l : BuddyPluginBeta .this .listeners ){
6603
+ for ( ChatManagerListener l : BuddyPluginBeta .this .listeners ){
6588
6604
6589
- try {
6590
- l .chatRemoved ( removed );
6605
+ try {
6606
+ l .chatRemoved ( removed );
6591
6607
6592
- }catch ( Throwable e ){
6608
+ }catch ( Throwable e ){
6593
6609
6594
- Debug .out ( e );
6595
- }
6610
+ Debug .out ( e );
6596
6611
}
6597
6612
}
6598
6613
}
0 commit comments