~ubuntu-branches/ubuntu/hardy/exim4/hardy-proposed

« back to all changes in this revision

Viewing changes to src/store.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Haber
  • Date: 2005-07-02 06:08:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050702060834-qk17pd52kb9nt3bj
Tags: 4.52-1
* new upstream version 4.51. (mh)
  * adapt 70_remove_exim-users_references
  * remove 37_gnutlsparams
  * adapt 36_pcre
  * adapt 31_eximmanpage
* fix package priorities to have them in sync with override again. (mh)
* Fix error in nb (Norwegian) translation.
  Thanks to Helge Hafting. (mh). Closes: #315775
* Standards-Version: 3.6.2, no changes needed. (mh)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Cambridge: exim/exim-src/src/store.c,v 1.2 2005/01/04 10:00:42 ph10 Exp $ */
 
2
 
1
3
/*************************************************
2
4
*     Exim - an Internet mail transport agent    *
3
5
*************************************************/
4
6
 
5
 
/* Copyright (c) University of Cambridge 1995 - 2004 */
 
7
/* Copyright (c) University of Cambridge 1995 - 2005 */
6
8
/* See the file NOTICE for conditions of use and distribution. */
7
9
 
8
10
/* Exim gets and frees all its store through these functions. In the original
31
33
  after accepting a message when multiple messages are received by a single
32
34
  process. Resetting happens at some other times as well, usually fairly
33
35
  locally after some specific processing that needs working store.
 
36
 
 
37
. There is a separate pool (POOL_SEARCH) that is used only for lookup storage.
 
38
  This means it can be freed when search_tidyup() is called to close down all
 
39
  the lookup caching.
34
40
*/
35
41
 
36
42
 
53
59
 
54
60
#define STORE_BLOCK_SIZE 8192
55
61
 
 
62
/* store_reset() will not free the following block if the last used block has
 
63
less than this much left in it. */
 
64
 
 
65
#define STOREPOOL_MIN_SIZE 256
 
66
 
56
67
/* Structure describing the beginning of each big block. */
57
68
 
58
69
typedef struct storeblock {
74
85
 
75
86
int store_pool = POOL_PERM;
76
87
 
77
 
static storeblock *chainbase[2] = { NULL, NULL };
78
 
static storeblock *current_block[2] = { NULL, NULL };
79
 
static void *next_yield[2] = { NULL, NULL };
80
 
static int yield_length[2] = { -1, -1 };
 
88
static storeblock *chainbase[3] = { NULL, NULL, NULL };
 
89
static storeblock *current_block[3] = { NULL, NULL, NULL };
 
90
static void *next_yield[3] = { NULL, NULL, NULL };
 
91
static int yield_length[3] = { -1, -1, -1 };
81
92
 
82
93
/* pool_malloc holds the amount of memory used by the store pools; this goes up
83
94
and down as store is reset or released. nonpool_malloc is the total got by
91
102
NULL. This enables string_cat() to optimize its store handling for very long
92
103
strings. That's why the variable is global. */
93
104
 
94
 
void *store_last_get[2] = { NULL, NULL};
 
105
void *store_last_get[3] = { NULL, NULL, NULL };
95
106
 
96
107
 
97
108
 
131
142
  {
132
143
  int length = (size <= STORE_BLOCK_SIZE)? STORE_BLOCK_SIZE : size;
133
144
  int mlength = length + ALIGNED_SIZEOF_STOREBLOCK;
134
 
  storeblock *newblock;
135
 
 
136
 
  pool_malloc += mlength;           /* Used in pools */
137
 
  nonpool_malloc -= mlength;        /* Exclude from overall total */
138
 
 
139
 
  newblock = store_malloc(mlength);
140
 
  newblock->next = NULL;
141
 
  newblock->length = length;
142
 
 
143
 
  if (chainbase[store_pool] == NULL) chainbase[store_pool] = newblock;
144
 
    else current_block[store_pool]->next = newblock;
 
145
  storeblock *newblock = NULL;
 
146
 
 
147
  /* Sometimes store_reset() may leave a block for us; check if we can use it */
 
148
 
 
149
  if (current_block[store_pool] != NULL &&
 
150
      current_block[store_pool]->next != NULL)
 
151
    {
 
152
    newblock = current_block[store_pool]->next;
 
153
    if (newblock->length < length)
 
154
      {
 
155
      /* Give up on this block, because it's too small */
 
156
      store_free(newblock);
 
157
      newblock = NULL;
 
158
      }
 
159
    }
 
160
 
 
161
  /* If there was no free block, get a new one */
 
162
 
 
163
  if (newblock == NULL)
 
164
    {
 
165
    pool_malloc += mlength;           /* Used in pools */
 
166
    nonpool_malloc -= mlength;        /* Exclude from overall total */
 
167
    newblock = store_malloc(mlength);
 
168
    newblock->next = NULL;
 
169
    newblock->length = length;
 
170
    if (chainbase[store_pool] == NULL) chainbase[store_pool] = newblock;
 
171
      else current_block[store_pool]->next = newblock;
 
172
    }
145
173
 
146
174
  current_block[store_pool] = newblock;
147
 
  yield_length[store_pool] = length;
 
175
  yield_length[store_pool] = newblock->length;
148
176
  next_yield[store_pool] =
149
177
    (void *)((char *)current_block[store_pool] + ALIGNED_SIZEOF_STOREBLOCK);
150
178
  }
327
355
next_yield[store_pool] = (char *)ptr + (newlength % alignment);
328
356
current_block[store_pool] = b;
329
357
 
330
 
/* Free any subsequent blocks, if any */
 
358
/* Free any subsequent block. Do NOT free the first successor, if our
 
359
current block has less than 256 bytes left. This should prevent us from
 
360
flapping memory. However, keep this block only when it has the default size. */
 
361
 
 
362
if (yield_length[store_pool] < STOREPOOL_MIN_SIZE &&
 
363
    b->next != NULL &&
 
364
    b->next->length == STORE_BLOCK_SIZE)
 
365
  b = b->next;
331
366
 
332
367
bb = b->next;
333
368
b->next = NULL;