diff --git a/src/rsrv/camessage.c b/src/rsrv/camessage.c index c0f246e08..af0d1c189 100644 --- a/src/rsrv/camessage.c +++ b/src/rsrv/camessage.c @@ -439,7 +439,7 @@ struct client *client /* * user name will not change if there isnt enough memory */ - pMalloc = malloc(size); + pMalloc = casMalloc(size); if(!pMalloc){ send_err( mp, @@ -498,7 +498,7 @@ struct client *client /* * user name will not change if there isnt enough memory */ - pMalloc = malloc(size); + pMalloc = casMalloc(size); if(!pMalloc){ send_err( mp, @@ -896,7 +896,7 @@ struct client *client */ if(!pciu->pPutNotify){ pciu->pPutNotify = - (RSRVPUTNOTIFY *) calloc(1, sizeof(*pciu->pPutNotify)+size); + (RSRVPUTNOTIFY *) casCalloc(1, sizeof(*pciu->pPutNotify)+size); if(!pciu->pPutNotify){ putNotifyErrorReply(client, mp, ECA_ALLOCMEM); return; @@ -1037,7 +1037,7 @@ struct client *client ellGet(&rsrv_free_eventq); FASTUNLOCK(&rsrv_free_eventq_lck); if (!pevext) { - pevext = (struct event_ext *) malloc(size); + pevext = (struct event_ext *) casMalloc(size); if (!pevext) { SEND_LOCK(client); send_err( @@ -1581,6 +1581,7 @@ struct client *client unsigned sid; unsigned long count; ca_uint16_t type; + int spaceAvailOnFreeList; /* Exit quickly if channel not on this node */ status = db_name_to_addr( @@ -1601,9 +1602,12 @@ struct client *client } /* - * set true if max memory block drops below MAX_BLOCK_THRESHOLD + * stop further use of server if max block drops + * below MAX_BLOCK_THRESHOLD */ - if(casDontAllowSearchReplies){ + spaceAvailOnFreeList = ellCount(&rsrv_free_clientQ)>0 + && ellCount(&rsrv_free_addrq)>0; + if (casBelowMaxBlockThresh && !spaceAvailOnFreeList) { SEND_LOCK(client); send_err(mp, ECA_ALLOCMEM, @@ -1696,7 +1700,7 @@ unsigned cid FASTUNLOCK(&rsrv_free_addrq_lck); if (!pchannel) { pchannel = (struct channel_in_use *) - malloc(sizeof(*pchannel)); + casMalloc(sizeof(*pchannel)); if (!pchannel) { return NULL; } @@ -1874,7 +1878,7 @@ char *pformat, case IOC_READ_SYNC: case IOC_SNAPSHOT: default: - reply->m_cid = NULL; + reply->m_cid = ~0L; break; } @@ -2111,3 +2115,32 @@ LOCAL void access_rights_reply(struct channel_in_use *pciu) END_MSG(pclient); SEND_UNLOCK(pclient); } + + +/* + * casCalloc() + * + * (dont drop below some max block threshold) + */ +void *casCalloc(size_t count, size_t size) +{ + if (casBelowMaxBlockThresh) { + return NULL; + } + return calloc(count, size); +} + + +/* + * casMalloc() + * + * (dont drop below some max block threshold) + */ +void *casMalloc(size_t size) +{ + if (casBelowMaxBlockThresh) { + return NULL; + } + return malloc(size); +} + diff --git a/src/rsrv/cast_server.c b/src/rsrv/cast_server.c index c94b04ff6..713a82e53 100644 --- a/src/rsrv/cast_server.c +++ b/src/rsrv/cast_server.c @@ -388,7 +388,7 @@ struct client *create_udp_client(unsigned sock) UNLOCK_CLIENTQ; if(!client){ - client = (struct client *)malloc(sizeof(struct client)); + client = (struct client *)casMalloc(sizeof(struct client)); if(!client){ logMsg("CAS: no mem for new client\n", NULL, @@ -426,7 +426,7 @@ struct client *create_udp_client(unsigned sock) /* * user name initially unknown */ - client->pUserName = malloc(1); + client->pUserName = casMalloc(1); if(!client->pUserName){ semDelete(client->blockSem); free(client); @@ -437,7 +437,7 @@ struct client *create_udp_client(unsigned sock) /* * host name initially unknown */ - client->pHostName = malloc(1); + client->pHostName = casMalloc(1); if(!client->pHostName){ semDelete(client->blockSem); free(client->pUserName); diff --git a/src/rsrv/online_notify.c b/src/rsrv/online_notify.c index d2ef1f993..012d51ba8 100644 --- a/src/rsrv/online_notify.c +++ b/src/rsrv/online_notify.c @@ -162,10 +162,10 @@ int rsrv_online_notify_task() */ maxBlock = memFindMax(); if(maxBlock