From a877a8ed7b508eb8cc5f7911dfcec8b8612470b3 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Fri, 2 Jun 2017 16:20:44 +0100 Subject: Fixed memleaks, rearranged some code --- test/test_alltypes.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'test/test_alltypes.c') diff --git a/test/test_alltypes.c b/test/test_alltypes.c index 2975d2a..b6eb801 100644 --- a/test/test_alltypes.c +++ b/test/test_alltypes.c @@ -104,8 +104,7 @@ int main() { FILE *f=NULL; int er; - netbyte_store nb; - netbyte_store nb2; + netbyte_store *nb = malloc(sizeof(netbyte_store)); nb_u8 u8; nb_u8arr u8arr; nb_u16 u16; @@ -120,7 +119,7 @@ int main() printf("Start test\n"); - nb_init( &nb ); + nb_init( nb ); er = nb_u8_create( &u8, 0x10 ); if (er) printf("er create u8: %d\n",er); @@ -142,8 +141,8 @@ int main() pr_u8arr( &u8arr ); #if 1 - pr_store( &nb ); - er = nb_add_u8( &nb, &u8 ); + pr_store( nb ); + er = nb_add_u8( nb, &u8 ); if (er) printf("er add u8: %d\n",er); #endif @@ -156,54 +155,39 @@ int main() #endif #if 1 - pr_store( &nb ); - er = nb_add_u16( &nb, &u16 ); + pr_store( nb ); + er = nb_add_u16( nb, &u16 ); if (er) printf("er add u16: %d\n",er); #endif #if 1 - pr_store( &nb ); - er = nb_add_u32( &nb, &u32 ); + pr_store( nb ); + er = nb_add_u32( nb, &u32 ); if (er) printf("er add u32: %d\n",er); #endif #if 1 - pr_store( &nb ); - er = nb_add_u64( &nb, &u64 ); + pr_store( nb ); + er = nb_add_u64( nb, &u64 ); if (er) printf("er add u64: %d\n",er); #endif - pr_store( &nb ); - res = nb_create( &nb ); - pr_store( &nb ); + pr_store( nb ); + res = nb_create( nb ); + pr_store( nb ); printf("res 0x%x\n", res); f = fopen("test_alltypes.nb","w+"); - fwrite( res, 1, nb.size , f ); + fwrite( res, 1, nb->size , f ); fclose( f ); - /* - printf("LOAD:-----\n"); - nb_init( &nb2 ); - pr_store( &nb2 ); - nb_load( &nb2, res ); - pr_store( &nb2 ); - - printf( "->1 [%s]\n", ((nb_u8arr *)nb2.types[1].nb_val)->val ); - - __NBT_TYPED *t=0xf8; - nb_u8arr *v; - nb_type( &nb2, 1, &t ); - printf("get type: %02x\n", t ); - nb_val( &nb2, 1, (uint8_t **)&v ); - printf("get value: %02x\n", v->val ); - */ - free( res ); + nb_free(nb); + printf("End test\n"); return 0; -- cgit v1.2.3