~yolanda.robla/ubuntu/saucy/clamav/dep-8-tests

« back to all changes in this revision

Viewing changes to libclamav/mpool.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2009-11-02 23:27:19 UTC
  • mfrom: (0.35.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091102232719-61ay35095dhbuxfm
Tags: 0.95.3+dfsg-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop build-dep on electric-fence (in Universe)
  - Build-dep on libltdl3-dev instead of libltdl-dev for updating earlier
    releases more easily
  - Add apparmor profiles for clamd and freshclam along with maintainer
    script changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#define FREEPOISON 0xde
50
50
#endif
51
51
 
52
 
/* #define DEBUGMPOOL /\* DO NOT define *\/ */
 
52
/* #define DEBUGMPOOL */
 
53
/* #define EXIT_ON_FLUSH */
53
54
#ifdef DEBUGMPOOL
54
55
#define spam(...) cli_warnmsg( __VA_ARGS__)
55
56
#else
58
59
 
59
60
#include "mpool.h"
60
61
 
61
 
/* #define MIN_FRAGSIZE 4096    /\* 1m2.282s *\/ */
62
 
/* #define MIN_FRAGSIZE 8192    /\* 0m46.652s *\/ */
63
 
/* #define MIN_FRAGSIZE 16384   /\* 0m8.365s *\/ */
64
 
/* #define MIN_FRAGSIZE 32768   /\* 0m3.788s *\/ */
65
 
/* #define MIN_FRAGSIZE 65536   /\* 0m2.759s *\/ */
66
 
/* #define MIN_FRAGSIZE 131072  /\* 0m2.445s *\/ */
67
 
#define MIN_FRAGSIZE 262144     /* 0m2.343s */
68
 
/* #define MIN_FRAGSIZE 524288  /\* 0m2.387s *\/ */
69
 
/* #define MIN_FRAGSIZE 1048576 /\* 0m2.392s *\/ */
70
 
/* #define MIN_FRAGSIZE 2097152 /\* 0m2.402s *\/ */
71
 
/* #define MIN_FRAGSIZE 99688128 */
 
62
#define MIN_FRAGSIZE 262144
72
63
 
73
64
#if SIZEOF_VOID_P==8
74
65
static const unsigned int fragsz[] = {
75
 
16, /* 34660 */
76
 
24, /* 99132 */
77
 
32, /* 935424 */
78
 
40, /* 20825 */
79
 
48, /* 7338 */
80
 
56, /* 536414 */
81
 
64, /* 2853 */
82
 
72, /* 2355 */
83
 
80, /* 3701 */
84
 
88, /* 2665 */
85
 
96, /* 3719 */
86
 
104, /* 3739 */
87
 
112, /* 4104 */
88
 
120, /* 5151 */
89
 
128, /* 25576 */
90
 
136, /* 4340 */
91
 
144, /* 4308 */
92
 
152, /* 12219 */
93
 
160, /* 18013 */
94
 
168, /* 329 */
95
 
176, /* 343 */
96
 
184, /* 207 */
97
 
192, /* 227 */
98
 
200, /* 169 */
99
 
208, /* 188 */
100
 
216, /* 231 */
101
 
224, /* 175 */
102
 
232, /* 154 */
103
 
240, /* 179 */
104
 
248, /* 140 */
105
 
256, /* 141 */
106
 
264, /* 142 */
107
 
272, /* 163 */
108
 
280, /* 125 */
109
 
288, /* 142 */
110
 
296, /* 102 */
111
 
304, /* 96 */
112
 
312, /* 67 */
113
 
320, /* 15 */
114
 
328, /* 21 */
115
 
336, /* 21 */
116
 
344, /* 12 */
117
 
352, /* 11 */
118
 
360, /* 6 */
119
 
368, /* 15 */
120
 
376, /* 5 */
121
 
384, /* 5 */
122
 
392, /* 4 */
123
 
400, /* 3 */
124
 
408, /* 8 */
125
 
416, /* 5 */
126
 
424, /* 4 */
127
 
432, /* 4 */
128
 
440, /* 3 */
129
 
456, /* 1 */
130
 
464, /* 8 */
131
 
472, /* 3 */
132
 
488, /* 1 */
133
 
496, /* 4 */
134
 
504, /* 3 */
135
 
512, /* 1 */
136
 
520, /* 1 */
137
 
528, /* 6 */
138
 
536, /* 2 */
139
 
544, /* 1 */
140
 
560, /* 4 */
141
 
576, /* 2 */
142
 
592, /* 10 */
143
 
616, /* 2 */
144
 
624, /* 6 */
145
 
656, /* 1 */
146
 
680, /* 1 */
147
 
704, /* 1 */
148
 
720, /* 1 */
149
 
776, /* 1 */
150
 
2056, /* 8545 */
151
 
63504, /* 9 */
152
 
144760, /* 1 */
153
 
507976, /* 9 */
154
 
525800, /* 1 */
155
 
1051032, /* (0) */
156
 
2097152
157
 
/* ^^ This shouldn't be reached but it's a good fall back
158
 
 * MAX_ALLOCATION is 184549376 but that's really not need here */
 
66
/* SIZE        PERM    TEMP    ACT! */
 
67
     16, /*    7631    7189 USE/POW2 */
 
68
     24, /*   81785     114      USE */
 
69
     32, /* 1099428      78 USE/POW2 */
 
70
     40, /*   22466      69      USE */
 
71
     48, /*    7438      37      USE */
 
72
     56, /*    5567      32      USE */
 
73
     64, /*    2801      31 USE/POW2 */
 
74
     72, /*  610137      29      USE */
 
75
     80, /*    3579      28      USE */
 
76
     88, /*    2603      28      USE */
 
77
     96, /*    3535      27      USE */
 
78
    104, /*    3669      24      USE */
 
79
    112, /*    3897      23      USE */
 
80
    120, /*    5105      22      USE */
 
81
    128, /*    3097      22 USE/POW2 */
 
82
    136, /*    3977      21      USE */
 
83
    144, /*   32225      21      USE */
 
84
    152, /*   12384      20      USE */
 
85
    160, /*   17258      20      USE */
 
86
    176, /*     504      20      USE */
 
87
    192, /*     324      20      USE */
 
88
    216, /*     363      20      USE */
 
89
    240, /*     478      19      USE */
 
90
    256, /*     516      19 USE/POW2 */
 
91
    288, /*     249      19      USE */
 
92
    312, /*     741      18      USE */
 
93
    336, /*      47      18      USE */
 
94
    512, /*       1      18     POW2 */
 
95
   1024, /*       0      17     POW2 */
 
96
   2048, /*       0      16     POW2 */
 
97
   2056, /*   11408      16      USE */
 
98
   4096, /*       0      16     POW2 */
 
99
   8192, /*       0      14     POW2 */
 
100
   8736, /*       1      12      USE */
 
101
  10240, /*       1      11      USE */
 
102
  16384, /*       0       8     POW2 */
 
103
  20536, /*       1       7      USE */
 
104
  33704, /*       1       6      USE */
 
105
  37312, /*       1       5      USE */
 
106
  43800, /*       1       3      USE */
 
107
  63504, /*       9       3      USE */
 
108
  65536, /*       0       3     POW2 */
 
109
  89800, /*       1       2      USE */
 
110
 102624, /*       1       1      USE */
 
111
 131072, /*       0       1     POW2 */
 
112
 147296, /*       1       1      USE */
 
113
 262144, /*       0       1     POW2 */
 
114
 369280, /*       1       0      USE */
 
115
 507976, /*       9       0      USE */
 
116
 525976, /*       1       0      USE */
 
117
1048576, /*       0       0 USE/POW2 */
 
118
2097152,
 
119
4194304,
 
120
8388608,
 
121
 /* MAX_ALLOCATION is 184549376 but that's really not need here */
159
122
};
160
123
 
161
124
#else
162
125
 
163
126
static const unsigned int fragsz[] = {
164
 
8, /* 2268 */
165
 
12, /* 32386 */
166
 
16, /* 59865 */
167
 
20, /* 58019 */
168
 
24, /* 789268 */
169
 
28, /* 127523 */
170
 
32, /* 539890 */
171
 
36, /* 11729 */
172
 
40, /* 1840 */
173
 
44, /* 5492 */
174
 
48, /* 1662 */
175
 
52, /* 3855 */
176
 
56, /* 1781 */
177
 
60, /* 990 */
178
 
64, /* 984 */
179
 
68, /* 1370 */
180
 
72, /* 1923 */
181
 
76, /* 1778 */
182
 
80, /* 1076 */
183
 
84, /* 1591 */
184
 
88, /* 2084 */
185
 
92, /* 23812 */
186
 
96, /* 1873 */
187
 
100, /* 1863 */
188
 
104, /* 1923 */
189
 
108, /* 2177 */
190
 
112, /* 1724 */
191
 
116, /* 3424 */
192
 
120, /* 2098 */
193
 
124, /* 1308 */
194
 
128, /* 2291 */
195
 
132, /* 2032 */
196
 
136, /* 2825 */
197
 
140, /* 1477 */
198
 
144, /* 1594 */
199
 
148, /* 10617 */
200
 
152, /* 2696 */
201
 
156, /* 15313 */
202
 
160, /* 182 */
203
 
164, /* 144 */
204
 
168, /* 197 */
205
 
172, /* 144 */
206
 
176, /* 118 */
207
 
180, /* 85 */
208
 
184, /* 121 */
209
 
188, /* 105 */
210
 
192, /* 84 */
211
 
196, /* 85 */
212
 
200, /* 97 */
213
 
204, /* 90 */
214
 
208, /* 149 */
215
 
212, /* 83 */
216
 
216, /* 75 */
217
 
220, /* 98 */
218
 
224, /* 83 */
219
 
228, /* 73 */
220
 
232, /* 114 */
221
 
236, /* 63 */
222
 
240, /* 75 */
223
 
244, /* 65 */
224
 
248, /* 72 */
225
 
252, /* 67 */
226
 
256, /* 69 */
227
 
260, /* 73 */
228
 
264, /* 93 */
229
 
268, /* 69 */
230
 
272, /* 56 */
231
 
276, /* 68 */
232
 
280, /* 71 */
233
 
284, /* 72 */
234
 
288, /* 61 */
235
 
292, /* 41 */
236
 
296, /* 53 */
237
 
300, /* 42 */
238
 
304, /* 37 */
239
 
308, /* 30 */
240
 
312, /* 9 */
241
 
316, /* 5 */
242
 
320, /* 6 */
243
 
324, /* 13 */
244
 
328, /* 13 */
245
 
332, /* 8 */
246
 
336, /* 5 */
247
 
340, /* 5 */
248
 
344, /* 3 */
249
 
348, /* 7 */
250
 
352, /* 1 */
251
 
356, /* 4 */
252
 
360, /* 14 */
253
 
364, /* 2 */
254
 
368, /* 3 */
255
 
372, /* 2 */
256
 
376, /* 4 */
257
 
388, /* 4 */
258
 
392, /* 3 */
259
 
400, /* 3 */
260
 
404, /* 3 */
261
 
408, /* 3 */
262
 
412, /* 2 */
263
 
416, /* 3 */
264
 
420, /* 1 */
265
 
428, /* 4 */
266
 
432, /* 1 */
267
 
436, /* 2 */
268
 
452, /* 2 */
269
 
456, /* 8 */
270
 
464, /* 1 */
271
 
468, /* 2 */
272
 
480, /* 1 */
273
 
488, /* 4 */
274
 
496, /* 1 */
275
 
500, /* 1 */
276
 
504, /* 1 */
277
 
512, /* 1 */
278
 
520, /* 6 */
279
 
532, /* 1 */
280
 
536, /* 1 */
281
 
552, /* 4 */
282
 
572, /* 3 */
283
 
584, /* 9 */
284
 
588, /* 1 */
285
 
608, /* 1 */
286
 
612, /* 1 */
287
 
616, /* 6 */
288
 
644, /* 1 */
289
 
648, /* 1 */
290
 
676, /* 1 */
291
 
700, /* 1 */
292
 
712, /* 1 */
293
 
768, /* 1 */
294
 
772, /* 1 */
295
 
1028, /* 8545 */
296
 
63500, /* 9 */
297
 
144752, /* 1 */
298
 
253988, /* 9 */
299
 
525628, /* 1 */
300
 
1051032, /* (0) */
301
 
2097152
 
127
/* SIZE        PERM    TEMP    ACT! */
 
128
      8, /*    1992    7188 USE/POW2 */
 
129
     16, /*   49976     172 USE/POW2 */
 
130
     24, /*  995096     121      USE */
 
131
     32, /*  151077      68 USE/POW2 */
 
132
     40, /*   15175      58      USE */
 
133
     48, /*    7231      55      USE */
 
134
     56, /*  613432      47      USE */
 
135
     64, /*    1925      44 USE/POW2 */
 
136
     72, /*    3192      42      USE */
 
137
     80, /*    2782      40      USE */
 
138
     88, /*    3524      40      USE */
 
139
     96, /*    3395      40      USE */
 
140
    104, /*    3593      40      USE */
 
141
    112, /*   31850      40      USE */
 
142
    120, /*    5260      38      USE */
 
143
    128, /*    3231      38 USE/POW2 */
 
144
    136, /*    4785      38      USE */
 
145
    144, /*    3000      38      USE */
 
146
    152, /*   13384      38      USE */
 
147
    160, /*   14915      36      USE */
 
148
    168, /*     485      36      USE */
 
149
    176, /*     379      36      USE */
 
150
    184, /*     322      36      USE */
 
151
    192, /*     260      36      USE */
 
152
    200, /*     410      36      USE */
 
153
    208, /*     388      36      USE */
 
154
    216, /*     262      36      USE */
 
155
    224, /*     256      36      USE */
 
156
    232, /*     475      36      USE */
 
157
    248, /*     544      36      USE */
 
158
    256, /*     206      36     POW2 */
 
159
    264, /*     352      36      USE */
 
160
    280, /*     258      36      USE */
 
161
    296, /*     283      36      USE */
 
162
    304, /*     308      36      USE */
 
163
    312, /*     566      36      USE */
 
164
    328, /*      53      36      USE */
 
165
    376, /*      18      36      USE */
 
166
    616, /*       7      34      USE */
 
167
   1032, /*   11408      32      USE */
 
168
   2048, /*       0      32     POW2 */
 
169
   4096, /*       0      28     POW2 */
 
170
   5456, /*       1      20      USE */
 
171
   8192, /*       0      16     POW2 */
 
172
  10272, /*       1      14      USE */
 
173
  18656, /*       1      11      USE */
 
174
  21904, /*       1       6      USE */
 
175
  32768, /*       0       6     POW2 */
 
176
  44864, /*       1       4      USE */
 
177
  51240, /*       1       2      USE */
 
178
  65536, /*       0       2     POW2 */
 
179
 131072, /*       0       2     POW2 */
 
180
 147288, /*       1       2      USE */
 
181
 184624, /*       1       0      USE */
 
182
 253992, /*       9       0      USE */
 
183
 262144, /*       0       0     POW2 */
 
184
 525752, /*       1       0      USE */
 
185
1048576, /*       0       0 USE/POW2 */
 
186
2097152,
 
187
4194304,
 
188
8388608,
302
189
};
303
190
#endif
304
191
#define FRAGSBITS (sizeof(fragsz)/sizeof(fragsz[0]))
327
214
};
328
215
#define FRAG_OVERHEAD (offsetof(struct FRAG, fake))
329
216
 
330
 
#define align_to_voidptr(size) (((size) / sizeof(void *) + ((size) % sizeof(void *) != 0)) * sizeof(void *))
 
217
#define align_to_voidptr(size) (((size) / MAX(sizeof(void *), 8) + ((size) % MAX(sizeof(void *), 8) != 0)) * MAX(sizeof(void *), 8))
331
218
#define mpool_roundup(size) (FRAG_OVERHEAD + align_to_voidptr(size))
332
219
 
333
220
static unsigned int align_to_pagesize(struct MP *mp, unsigned int size) {
349
236
  struct MP mp, *mpool_p;
350
237
  unsigned int sz;
351
238
  memset(&mp, 0, sizeof(mp));
352
 
  mp.psize = getpagesize();
 
239
  mp.psize = cli_getpagesize();
353
240
  sz = align_to_pagesize(&mp, MIN_FRAGSIZE);
354
241
  mp.mpm.usize = align_to_voidptr(sizeof(struct MPMAP));
355
242
  mp.mpm.size = sz - align_to_voidptr(sizeof(mp));
359
246
  memset(mpool_p, ALLOCPOISON, sz);
360
247
#endif
361
248
  memcpy(mpool_p, &mp, sizeof(mp));
362
 
  spam("Map created @ %p->%p - size %u out of %u\n", mpool_p, (char *)mpool_p + mp.mpm.size, mp.mpm.usize, mp.mpm.size);
 
249
  spam("Map created @%p->%p - size %u out of %u - voidptr=%u\n", mpool_p, (char *)mpool_p + mp.mpm.size, mp.mpm.usize, mp.mpm.size, SIZEOF_VOID_P);
363
250
  return mpool_p;
364
251
}
365
252
 
380
267
  memset(mp, FREEPOISON, mpmsize + align_to_voidptr(sizeof(*mp)));
381
268
#endif
382
269
  munmap((void *)mp, mpmsize + align_to_voidptr(sizeof(*mp)));
383
 
  spam("Map destroyed @ %p\n", mp);
 
270
  spam("Map destroyed @%p\n", mp);
384
271
}
385
272
 
386
273
void mpool_flush(struct MP *mp) {
387
 
  size_t used = 0, mused;
388
 
  struct MPMAP *mpm_next = mp->mpm.next, *mpm;
389
 
 
390
 
  while((mpm = mpm_next)) {
391
 
    mpm_next = mpm->next;
392
 
#ifdef CL_DEBUG
393
 
    memset((char *)mpm + align_to_pagesize(mp, mpm->usize), FREEPOISON, mpm->size - align_to_pagesize(mp, mpm->usize));
394
 
#endif
395
 
    munmap((char *)mpm + align_to_pagesize(mp, mpm->usize), mpm->size - align_to_pagesize(mp, mpm->usize));
396
 
    mpm->size = align_to_pagesize(mp, mpm->usize);
397
 
    used += mpm->size;
398
 
  }
399
 
  mused = align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(*mp)));
400
 
  if (mused < mp->mpm.size) {
401
 
#ifdef CL_DEBUG
402
 
    memset((char *)&mp->mpm + mused, FREEPOISON, mp->mpm.size - mused);
403
 
#endif
404
 
    munmap((char *)&mp->mpm + mused, mp->mpm.size - mused);
405
 
    mp->mpm.size = mused;
406
 
  }
407
 
  used += mp->mpm.size;
408
 
  spam("Map flushed @ %p, in use: %lu\n", mp, used);
 
274
    size_t used = 0, mused;
 
275
    struct MPMAP *mpm_next = mp->mpm.next, *mpm;
 
276
 
 
277
#ifdef EXIT_ON_FLUSH
 
278
    exit(0);
 
279
#endif
 
280
 
 
281
    while((mpm = mpm_next)) {
 
282
        mpm_next = mpm->next;
 
283
        mused = align_to_pagesize(mp, mpm->usize);
 
284
        if(mused < mpm->size) {
 
285
#ifdef CL_DEBUG
 
286
            memset((char *)mpm + mused, FREEPOISON, mpm->size - mused);
 
287
#endif
 
288
            munmap((char *)mpm + mused, mpm->size - mused);
 
289
            mpm->size = mused;
 
290
        }
 
291
        used += mpm->size;
 
292
    }
 
293
 
 
294
    mused = align_to_pagesize(mp, mp->mpm.usize + align_to_voidptr(sizeof(*mp)));
 
295
    if (mused < mp->mpm.size + align_to_voidptr(sizeof(*mp))) {
 
296
#ifdef CL_DEBUG
 
297
        memset((char *)mp + mused, FREEPOISON, mp->mpm.size + align_to_voidptr(sizeof(*mp)) - mused);
 
298
#endif
 
299
        munmap((char *)mp + mused, mp->mpm.size + align_to_voidptr(sizeof(*mp)) - mused);
 
300
        mp->mpm.size = mused - align_to_voidptr(sizeof(*mp));
 
301
    }
 
302
    used += mp->mpm.size;
 
303
    spam("Map flushed @%p, in use: %lu\n", mp, used);
409
304
}
410
305
 
411
306
int mpool_getstats(const struct cl_engine *eng, size_t *used, size_t *total)
443
338
 
444
339
  /* Case 1: We have a free'd frag */
445
340
  if((f = mp->avail[sbits])) {
446
 
    spam("malloc %p size %u (freed)\n", f, mpool_roundup(size));
 
341
    spam("malloc @%p size %u (freed)\n", f, align_to_voidptr(size + FRAG_OVERHEAD));
447
342
    mp->avail[sbits] = f->u.next;
448
343
    f->u.sbits = sbits;
449
344
#ifdef CL_DEBUG
462
357
  while(mpm) {
463
358
    if(mpm->size - mpm->usize >= needed) {
464
359
      f = (struct FRAG *)((char *)mpm + mpm->usize);
465
 
      spam("malloc %p size %u (hole)\n", f, mpool_roundup(size));
 
360
      spam("malloc @%p size %u (hole)\n", f, align_to_voidptr(size + FRAG_OVERHEAD));
466
361
      mpm->usize += needed;
467
362
      f->u.sbits = sbits;
468
363
#ifdef CL_DEBUG
493
388
  mpm->next = mp->mpm.next;
494
389
  mp->mpm.next = mpm;
495
390
  f = (struct FRAG *)((char *)mpm + align_to_voidptr(sizeof(*mpm)));
496
 
  spam("malloc %p size %u (new map)\n", f, mpool_roundup(size));
 
391
  spam("malloc @%p size %u (new map)\n", f, align_to_voidptr(size + FRAG_OVERHEAD));
497
392
  f->u.sbits = sbits;
498
393
#ifdef CL_DEBUG
499
394
  f->magic = MPOOLMAGIC;
514
409
  sbits = f->u.sbits;
515
410
  f->u.next = mp->avail[sbits];
516
411
  mp->avail[sbits] = f;
517
 
  spam("free @ %p\n", f);
 
412
  spam("free @%p\n", f);
518
413
}
519
414
 
520
415
void *mpool_calloc(struct MP *mp, size_t nmemb, size_t size) {
533
428
  void *new_ptr;
534
429
  if (!ptr) return mpool_malloc(mp, size);
535
430
 
536
 
  spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->u.sbits), size);
537
431
  if(!size || !(csize = from_bits(f->u.sbits))) {
538
432
    cli_errmsg("mpool_realloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
539
433
    return NULL;
540
434
  }
541
435
  csize -= FRAG_OVERHEAD;
542
 
  if (csize >= size && (!f->u.sbits || from_bits(f->u.sbits-1)-FRAG_OVERHEAD < size))
 
436
  if (csize >= size && (!f->u.sbits || from_bits(f->u.sbits-1)-FRAG_OVERHEAD < size)) {
 
437
    spam("free @%p\n", f);
 
438
    spam("malloc @%p size %u (self)\n", f, align_to_voidptr(size + FRAG_OVERHEAD));
543
439
    return ptr;
 
440
  }
544
441
  if (!(new_ptr = mpool_malloc(mp, size)))
545
442
    return NULL;
546
443
  memcpy(new_ptr, ptr, csize <= size ? csize : size);
549
446
}
550
447
 
551
448
void *mpool_realloc2(struct MP *mp, void *ptr, size_t size) {
552
 
  struct FRAG *f = (struct FRAG *)((char *)ptr - FRAG_OVERHEAD);
553
 
  unsigned int csize;
554
 
  void *new_ptr;
555
 
 
556
 
  if (!ptr) return mpool_malloc(mp, size);
557
 
 
558
 
  spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->u.sbits), size);
559
 
  if(!size || !(csize = from_bits(f->u.sbits))) {
560
 
    cli_errmsg("mpool_realloc2(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
 
449
    void *new_ptr = mpool_realloc(mp, ptr, size);
 
450
    if(new_ptr)
 
451
        return new_ptr;
561
452
    mpool_free(mp, ptr);
562
453
    return NULL;
563
 
  }
564
 
  csize -= FRAG_OVERHEAD;
565
 
  if (csize >= size && (!f->u.sbits || from_bits(f->u.sbits-1)-FRAG_OVERHEAD < size))
566
 
    return ptr;
567
 
  if ((new_ptr = mpool_malloc(mp, size)))
568
 
    memcpy(new_ptr, ptr, csize);
569
 
  mpool_free(mp, ptr);
570
 
  return new_ptr;
571
454
}
572
455
 
573
456
unsigned char *cli_mpool_hex2str(mpool_t *mp, const unsigned char *hex) {