diff options
author | FreeArtMan <dos21h@gmail.com> | 2017-06-02 16:20:44 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2017-06-02 16:20:44 +0100 |
commit | a877a8ed7b508eb8cc5f7911dfcec8b8612470b3 (patch) | |
tree | 00b901522f01bad243cb14afc2f5ca8698ce5a37 /test/test_save.c | |
parent | 65fb94f8fd98d343ae49f7d7e576418dba5a5d46 (diff) | |
download | netbytes-a877a8ed7b508eb8cc5f7911dfcec8b8612470b3.tar.gz netbytes-a877a8ed7b508eb8cc5f7911dfcec8b8612470b3.zip |
Fixed memleaks, rearranged some code
Diffstat (limited to 'test/test_save.c')
-rw-r--r-- | test/test_save.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/test/test_save.c b/test/test_save.c index 6e3be63..6c1f0ae 100644 --- a/test/test_save.c +++ b/test/test_save.c @@ -59,8 +59,8 @@ int main() { FILE *f=NULL; int er; - netbyte_store nb; - netbyte_store nb2; + netbyte_store *nb=malloc(sizeof(netbyte_store)); + netbyte_store *nb2=malloc(sizeof(netbyte_store)); nb_u8 u8; nb_u8arr u8arr; const int len = 11; @@ -69,7 +69,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); @@ -82,45 +82,51 @@ 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 #if 1 - pr_store( &nb ); - er = nb_add_u8arr( &nb, &u8arr ); + pr_store( nb ); + er = nb_add_u8arr( nb, &u8arr ); if (er) printf("er add u8arr: %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.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 ); + nb_init( nb2 ); + pr_store( nb2 ); + - printf( "->1 [%s]\n", ((nb_u8arr *)nb2.types[1].nb_val)->val ); + 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 ); + nb_type( nb2, 1, &t ); printf("get type: %02x\n", t ); - nb_val( &nb2, 1, (uint8_t **)&v ); + nb_val( nb2, 1, (uint8_t **)&v ); printf("get value: %02x\n", v->val ); - free( res ); + + nb_free(nb); + nb_free(nb2); + free( res ); res = NULL; printf("End test\n"); return 0; |