Ticket #168: jabberd2_limit_nadcache.diff
| File jabberd2_limit_nadcache.diff, 2.9 KB (added by markdoliner, 15 months ago) |
|---|
-
util/nad.c
117 117 nad_cache_t nad_cache_new(void) 118 118 { 119 119 nad_cache_t cache; 120 cache = malloc(sizeof(nad_cache_t)); 121 *cache = NULL; 120 cache = malloc(sizeof(struct nad_cache_st)); 121 cache->len = 0; 122 cache->nads = malloc(sizeof(struct nad_st **)); 123 *cache->nads = NULL; 122 124 123 125 #ifdef NAD_DEBUG 124 126 if(_nad_alloc_tracked == NULL) _nad_alloc_tracked = xhash_new(501); … … 133 135 void nad_cache_free(nad_cache_t cache) 134 136 { 135 137 nad_t cur; 136 while((cur = *cache ) != NULL)138 while((cur = *cache->nads) != NULL) 137 139 { 138 *cache = cur->next;140 *cache->nads = cur->next; 139 141 free(cur->elems); 140 142 free(cur->attrs); 141 143 free(cur->nss); … … 143 145 free(cur->depths); 144 146 free(cur); 145 147 } 148 free(cache->nads); 146 149 free(cache); 147 150 } 148 151 … … 154 157 #ifndef NAD_DEBUG 155 158 /* If cache==NULL, then this NAD is not in a cache */ 156 159 157 if ((cache!=NULL) && (*cache != NULL))160 if ((cache!=NULL) && (*cache->nads != NULL)) 158 161 { 159 nad = *cache; 160 *cache = nad->next; 162 nad = *cache->nads; 163 *cache->nads = nad->next; 164 cache->len--; 161 165 nad->ccur = nad->ecur = nad->acur = nad->ncur = 0; 162 166 nad->scope = -1; 163 167 nad->cache = cache; … … 232 236 xhash_put(_nad_free_tracked, pstrdup(xhash_pool(_nad_free_tracked), loc), (void *) nad); 233 237 } 234 238 #else 235 /* If nad->cache != NULL, then put back into cache, otherwise this nad is not in a cache */ 236 237 if (nad->cache != NULL) { 238 nad->next = *(nad->cache); 239 *(nad->cache) = nad; 239 /* If nad->cache != NULL, there are less than 100 nads in the 240 * cache and this nad isn't gigantic then put back into cache, 241 * otherwise we should just free this nad */ 242 if (nad->cache != NULL && nad->cache->len < 100 && nad->elen < 100000 && nad->alen < 100000 && nad->clen < 100000 && nad->dlen < 100000) { 243 nad->next = *(nad->cache->nads); 244 *(nad->cache->nads) = nad; 245 nad->cache->len++; 240 246 return; 241 247 } 242 248 #endif -
util/nad.h
49 49 # include <config.h> 50 50 #endif 51 51 52 #ifdef HAVE_SYS_TYPES_H 53 # include <sys/types.h> 54 #endif 55 52 56 /* jabberd2 Windows DLL */ 53 57 #ifndef JABBERD2_API 54 58 # ifdef _WIN32 … … 62 66 # endif /* _WIN32 */ 63 67 #endif /* JABBERD2_API */ 64 68 65 typedef struct nad_ st **nad_cache_t;69 typedef struct nad_cache_st *nad_cache_t; 66 70 67 71 struct nad_elem_st { 68 72 int parent; … … 102 106 struct nad_st *next; /* for keeping a list of nads */ 103 107 } *nad_t; 104 108 109 struct nad_cache_st 110 { 111 struct nad_st **nads; 112 size_t len; 113 }; 114 105 115 /** create a new cache, simple pointer to a list of nads */ 106 116 JABBERD2_API nad_cache_t nad_cache_new(void); 107 117
