File: leak2.c

package info (click to toggle)
xbae 4.60.4-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 5,892 kB
  • sloc: ansic: 22,088; sh: 8,306; makefile: 520; tcl: 1
file content (61 lines) | stat: -rw-r--r-- 1,481 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* $Header: /cvsroot/xbae/Xbae/examples/tests/leak2.c,v 1.3 2003/06/21 09:38:46 dannybackx Exp $
   From:        Yasushi Yamasaki <yamapu@osk3.3web.ne.jp>
   To:          lesstif@hungry.com
   Subject:     bug report
   Date:        Sun, 30 Aug 1998 23:55:47 +0900
   Cc:          yamapu@osk3.3web.ne.jp
 */

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include <Xm/Xm.h>
#include <Xbae/Matrix.h>

typedef struct AppRes {
	int	numIter;
} AppRes;
AppRes	appres;

XtResource	resources[] = {
	{ "numIter", "NumIter", XtRInt, sizeof(int),
		XtOffsetOf(AppRes, numIter), XtRImmediate, 1000 },
};

int
main(int argc, char *argv[])
{
	XtAppContext app;
	Widget shell, w;
	void *before;
	void *after;
	int iter = 0;
	int diff = 0;
	int total = 0;

	shell = XtAppInitialize(&app, "Test", NULL, 0,
		&argc, argv, NULL, NULL, 0);
	XtVaGetApplicationResources(shell, &appres, resources, XtNumber(resources), NULL);

	while (iter < appres.numIter) {
		before = sbrk((ptrdiff_t) 0);
		w = XtCreateWidget("name", xbaeMatrixWidgetClass, shell, NULL, 0);
		XtDestroyWidget(w);
		after = sbrk((ptrdiff_t) 0);
		if ((int)((char *)after - (char *)before) > 0) {
			if (iter != 0) {
				/*
				printf("%i %i %p %i\n",
				iter, iter - diff, after - before,
				(after - before) / (iter - diff));
				*/
				total += (int)((char *)after - (char*)before);
			}
			diff = iter;
		}
		iter++;
	}
	printf("leaking %i bytes per Create/Destroy\n", total / iter);
	exit((int)(total / iter));
}