File:  [ELWIX - Embedded LightWeight unIX -] / libaitsess / contrib / Attic / test_mem.c
Revision 1.1.2.3: download - view: text, annotated - select for diffs - revision graph
Tue Feb 28 00:25:25 2012 UTC (12 years, 8 months ago) by misho
Branches: sess3_1
fix bug into bucket calculation at mpool_free()

#include <stdio.h>
#include <aitsess.h>


int
main(int argc, char **argv)
{
	mpool_t *mp;
	void *addr;
	int i;

	for (i = 0; i < 3; i++) {
		addr = malloc(4000);
		printf("addr=%p\n", addr);
		free(addr);
	}

	mp = mpool_init();
	if (!mp) {
		printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
		return 1;
	}

	for (i = 0; i < 3; i++) {
	addr = mpool_malloc(mp, 4000, "mdaaa 4000");
	if (!addr) {
		printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
		mpool_destroy(&mp);
		return 2;
	}
	printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));

	strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n", 
			mpool_getsizebyaddr(addr));
	mpool_free(mp, addr, 0);
	}

	mpool_purge(mp, 1);

	mpool_destroy(&mp);
	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>