Changeset 4007 for trunk/oscam.c


Ignore:
Timestamp:
11/27/10 13:09:54 (10 years ago)
Author:
_network
Message:

fix bug when increasing cache and always remove oldest entry

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oscam.c

    r4006 r4007  
    405405    pthread_mutex_lock(&cwcache_lock);
    406406    struct s_ecm *ecmc;
    407     if (cwcache->next != NULL) { //keep it at least on one entry big
    408         for (ecmc=cwcache; ecmc->next->next ; ecmc=ecmc->next) ; //find last element
    409         if (cwidx==ecmc->next)
    410             cwidx = cwcache;
    411         NULLFREE(ecmc->next); //free last element
     407    if (cwidx->next) {
     408        if (cwidx->next->next) {
     409            ecmc=cwidx->next->next;
     410            NULLFREE(cwidx->next);
     411            cwidx->next=ecmc;
     412        } else
     413            NULLFREE(cwidx->next);
     414    } else {
     415        ecmc=cwcache->next;
     416        NULLFREE(cwcache);
     417        cwcache=ecmc;
    412418    }
    413419    pthread_mutex_unlock(&cwcache_lock);
     
    624630        ecmc->next = malloc(sizeof(struct s_ecm));
    625631        if (ecmc->next)
    626             memset(ecmc, 0, sizeof(struct s_ecm));
     632            memset(ecmc->next, 0, sizeof(struct s_ecm));
    627633        pthread_mutex_unlock(&cwcache_lock);
    628634
     
    631637        ecmc->next = malloc(sizeof(struct s_ecm));
    632638        if (ecmc->next)
    633             memset(ecmc, 0, sizeof(struct s_ecm));
     639            memset(ecmc->next, 0, sizeof(struct s_ecm));
    634640    } else {
    635641        cs_log("max connections reached -> reject client %s", cs_inet_ntoa(ip));
Note: See TracChangeset for help on using the changeset viewer.