Apply the changes that Derrell Lipman supplied ...
[Samba/gebeck_regimport.git] / source3 / lib / talloctort.c
blobad5de38581dbe1c4fdd5bf386aaa0f8c7214e628
1 /*
2 Unix SMB/CIFS implementation.
3 Samba temporary memory allocation functions -- torturer
4 Copyright (C) 2001 by Martin Pool <mbp@samba.org>
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.
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.
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.
21 #include "includes.h"
23 #define NCTX 10
24 #define NOBJ 20
26 int main(void)
28 int i;
29 TALLOC_CTX *ctx[NCTX];
31 for (i = 0; i < NCTX; i++) {
32 ctx[i] = talloc_init("torture(%d)", i);
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);
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);
49 memset(p, 'A' + j, size);
53 for (i = 0; i < NCTX; i++) {
54 printf("talloc@%p %-40s %dkB\n", ctx[i],
55 talloc_pool_name(ctx[i]),
56 talloc_pool_size(ctx[i]) >> 10);
59 printf("%s", talloc_describe_all(ctx[0]));
61 for (i = NCTX - 1; i >= 0; i--)
62 talloc_destroy(ctx[i]);
64 return 0;