From: martinahansen Date: Mon, 21 Jul 2008 23:42:56 +0000 (+0000) Subject: updated upload_to_ucsc wiki and added a secure free to c code X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0a5d4a1310e831dd928af54a5ae9921e49efd55d;p=biopieces.git updated upload_to_ucsc wiki and added a secure free to c code git-svn-id: http://biopieces.googlecode.com/svn/trunk@186 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/code_c/Maasha/src/inc/common.h b/code_c/Maasha/src/inc/common.h index fcc01bf..41096bc 100644 --- a/code_c/Maasha/src/inc/common.h +++ b/code_c/Maasha/src/inc/common.h @@ -55,7 +55,7 @@ struct list_int /* Print error message to stderr and exit. */ -void die( char *error_msg ); +void die( char *error_msg ); /* Print warning message to stderr. */ void warn( char *warn_msg ); @@ -65,23 +65,25 @@ void warn( char *warn_msg ); /* Get a pointer with a given size of allocated memory. */ -void *mem_get( size_t size ); +void *mem_get( size_t size ); /* Get a pointer with a given size of allocated and zero'ed memory. */ -void *mem_get_zero( size_t size ); +void *mem_get_zero( size_t size ); /* Resize allocated memory for a given pointer. */ -void *mem_resize( void* pt, size_t size ); +void *mem_resize( void* pt, size_t size ); /* Resize allocated memory for a given pointer with extra memory zero'ed. */ void *mem_resize_zero( void* pt, size_t old_size, size_t new_size ); /* Clone a structure in memory and return a pointer to the clone. */ -void *mem_clone( void *old_pt, size_t size ); +void *mem_clone( void *old_pt, size_t size ); /* Free memory from a given pointer. */ -void mem_free( void *pt ); +void mem_free( void *pt ); +/* Zero and then free memory from a given pointer. */ +void mem_free( void *pt ); /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ARRAYS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ @@ -94,13 +96,13 @@ bool binary_search_array( int *array, int array_size, int val ); /* Remove the last char from a string. */ -void chop( char *string ); +void chop( char *string ); /* Remove the last char from a string if the char is a newline (safer than chop). */ -void chomp( char *string ); +void chomp( char *string ); /* Split a given line and a delimiter return the split result as a list. */ -void split( char *string, char delimit, struct list **fields ); +void split( char *string, char delimit, struct list **fields ); /* Mockup version of Perl substr. */ char *substr( char *string, int offset, int len ); diff --git a/code_c/Maasha/src/lib/common.c b/code_c/Maasha/src/lib/common.c index 8203a2c..c84a02a 100644 --- a/code_c/Maasha/src/lib/common.c +++ b/code_c/Maasha/src/lib/common.c @@ -135,6 +135,22 @@ void mem_free( void *pt ) } +void mem_free_zero( void *pt ) +{ + /* Martin A. Hansen, July 2008 */ + + /* Zero and then free memory from a given pointer. */ + + if ( pt != NULL ) + { + ZERO( pt ); + free( pt ); + + pt = NULL; + } +} + + /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ARRAYS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/