~ubuntu-branches/ubuntu/maverick/samba/maverick-proposed

« back to all changes in this revision

Viewing changes to source/lib/talloctort.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-10-15 12:31:58 UTC
  • Revision ID: james.westby@ubuntu.com-20041015123158-aokykzdqkdgy6dfx
Tags: upstream-3.0.7
ImportĀ upstreamĀ versionĀ 3.0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   Unix SMB/CIFS implementation.
 
3
   Samba temporary memory allocation functions -- torturer
 
4
   Copyright (C) 2001 by Martin Pool <mbp@samba.org>
 
5
   
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 2 of the License, or
 
9
   (at your option) any later version.
 
10
   
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
   
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
*/
 
20
 
 
21
#include "includes.h"
 
22
 
 
23
#define NCTX 10
 
24
#define NOBJ 20
 
25
 
 
26
int main(void)
 
27
{
 
28
        int i;
 
29
        TALLOC_CTX *ctx[NCTX];
 
30
 
 
31
        for (i = 0; i < NCTX; i++) {
 
32
                ctx[i] = talloc_init("torture(%d)", i);
 
33
        }
 
34
 
 
35
        for (i = 0; i < NCTX; i++) {
 
36
                int j;
 
37
                for (j = 0; j < NOBJ; j++) {
 
38
                        char *p;
 
39
                        size_t size = 1<<(i/3+j);
 
40
 
 
41
                        p = talloc(ctx[i], size);
 
42
                        if (!p) {
 
43
                                fprintf(stderr,
 
44
                                        "failed to talloc %.0f bytes\n",
 
45
                                        (double) size);
 
46
                                exit(1);
 
47
                        }
 
48
 
 
49
                        memset(p, 'A' + j, size);
 
50
                }
 
51
        }
 
52
 
 
53
        for (i = 0; i < NCTX; i++) {
 
54
                printf("talloc@%p %-40s %ldkB\n", ctx[i],
 
55
                       talloc_pool_name(ctx[i]),
 
56
                       (unsigned long)talloc_pool_size(ctx[i]) >> 10);
 
57
        }
 
58
 
 
59
        printf("%s", talloc_describe_all(ctx[0]));
 
60
 
 
61
        for (i = NCTX - 1; i >= 0; i--)
 
62
                talloc_destroy(ctx[i]);
 
63
 
 
64
        return 0;
 
65
}