Navigation


Changeset 691:78b665400097 in freeDiameter for libfdproto/sessions.c


Ignore:
Timestamp:
Jan 20, 2011, 7:44:27 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Cleanup all pthread_cleanup_push / pop pairs so that pop is always called after push, or ASSERT(0) is some grave errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/sessions.c

    r686 r691  
    176176                if (FD_IS_LIST_EMPTY(&exp_sentinel)) {
    177177                        /* Just wait for a change or cancelation */
    178                         CHECK_POSIX_DO( pthread_cond_wait( &exp_cond, &exp_lock ), break );
     178                        CHECK_POSIX_DO( pthread_cond_wait( &exp_cond, &exp_lock ), break /* this might not pop the cleanup handler, but since we ASSERT(0), it is not the big issue... */ );
    179179                        /* Restart the loop on wakeup */
    180180                        goto again;
     
    207207        } while (1);
    208208       
    209         TRACE_DEBUG(INFO, "An error occurred in session module! Expiry thread is terminating...");
     209        TRACE_DEBUG(INFO, "A system error occurred in session module! Expiry thread is terminating...");
    210210        ASSERT(0);
    211211        return NULL;
     
    442442                /* We added a new expiring element, we must signal */
    443443                if (li == &exp_sentinel) {
    444                         CHECK_POSIX( pthread_cond_signal(&exp_cond) );
     444                        CHECK_POSIX_DO( pthread_cond_signal(&exp_cond), { ASSERT(0); } ); /* if it fails, we might not pop the cleanup handlers, but this should not happen -- and we'd have a serious problem otherwise */
    445445                }
    446446               
     
    458458                /* We're done */
    459459                pthread_cleanup_pop(0);
    460                 CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) );
     460                CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); } ); /* if it fails, we might not pop the cleanup handler, but this should not happen -- and we'd have a serious problem otherwise */
    461461        }
    462462       
     
    540540        /* We added a new expiring element, we must signal if it was in first position */
    541541        if (session->expire.prev == &exp_sentinel) {
    542                 CHECK_POSIX( pthread_cond_signal(&exp_cond) );
     542                CHECK_POSIX_DO( pthread_cond_signal(&exp_cond), { ASSERT(0); /* so that we don't have a pending cancellation handler */ } );
    543543        }
    544544
     
    573573       
    574574        /* Unlink and invalidate */
    575         CHECK_FCT( pthread_mutex_lock( H_LOCK(sess->hash) ) );
     575        CHECK_POSIX( pthread_mutex_lock( H_LOCK(sess->hash) ) );
    576576        pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(sess->hash) );
    577         CHECK_FCT( pthread_mutex_lock( &exp_lock ) );
     577        CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
    578578        fd_list_unlink( &sess->chain_h );
    579579        fd_list_unlink( &sess->expire ); /* no need to signal the condition here */
    580580        sess->eyec = 0xdead;
    581         CHECK_FCT( pthread_mutex_unlock( &exp_lock ) );
     581        CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise cleanup handler is not pop'd */ } );
    582582        pthread_cleanup_pop(0);
    583         CHECK_FCT( pthread_mutex_unlock( H_LOCK(sess->hash) ) );
     583        CHECK_POSIX( pthread_mutex_unlock( H_LOCK(sess->hash) ) );
    584584       
    585585        /* Now destroy all states associated -- we don't take the lock since nobody can access this session anymore (in theory) */
     
    614614        CHECK_POSIX( pthread_mutex_lock( H_LOCK(sess->hash) ) );
    615615        pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(sess->hash) );
    616         CHECK_POSIX( pthread_mutex_lock( &exp_lock ) );
     616        CHECK_POSIX_DO( pthread_mutex_lock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } );
    617617        if (FD_IS_LIST_EMPTY(&sess->states)) {
    618618                fd_list_unlink( &sess->chain_h );
     
    622622                free(sess);
    623623        }
    624         CHECK_POSIX( pthread_mutex_unlock( &exp_lock ) );
     624        CHECK_POSIX_DO( pthread_mutex_unlock( &exp_lock ), { ASSERT(0); /* otherwise, cleanup not poped on FreeBSD */ } );
    625625        pthread_cleanup_pop(0);
    626626        CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) );
     
    635635        struct fd_list * li;
    636636        int already = 0;
     637        int ret = 0;
    637638       
    638639        TRACE_ENTRY("%p %p %p", handler, session, state);
     
    644645                       
    645646        /* Create the new state object */
    646         CHECK_MALLOC(new = malloc(sizeof(struct state)) );
     647        CHECK_MALLOC_DO(new = malloc(sizeof(struct state)), { ret = ENOMEM; goto out; } );
    647648        memset(new, 0, sizeof(struct state));
    648649       
     
    661662                if (st->hdl->id == handler->id) {
    662663                        TRACE_DEBUG(INFO, "A state was already stored for session '%s' and handler '%p', at location %p", session->sid, st->hdl, st->state);
    663                         already = 1;
     664                        already = EALREADY;
    664665                }
    665666               
     
    673674                free(new);
    674675        }
    675        
     676out:
     677        ;       
    676678        pthread_cleanup_pop(0);
    677679        CHECK_POSIX( pthread_mutex_unlock(&session->stlock) );
    678680       
    679         return already ? EALREADY : 0;
     681        return ret ?: already;
    680682}
    681683
Note: See TracChangeset for help on using the changeset viewer.