From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/registry/reg_cachehook.c | 2 +- source3/registry/reg_db.c | 4 ++-- source3/registry/reg_frontend.c | 2 +- source3/registry/reg_objects.c | 24 ++++++++++++------------ source3/registry/reg_printing.c | 14 +++++++------- 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'source3/registry') diff --git a/source3/registry/reg_cachehook.c b/source3/registry/reg_cachehook.c index 547eed392d..3b75cae1a5 100644 --- a/source3/registry/reg_cachehook.c +++ b/source3/registry/reg_cachehook.c @@ -78,7 +78,7 @@ REGISTRY_HOOK* reghook_cache_find( char *keyname ) /* prepend the string with a '\' character */ len = strlen( keyname ); - if ( !(key = malloc( len + 2 )) ) { + if ( !(key = SMB_MALLOC( len + 2 )) ) { DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n", keyname)); return NULL; diff --git a/source3/registry/reg_db.c b/source3/registry/reg_db.c index cd5ec18f02..5ac8329309 100644 --- a/source3/registry/reg_db.c +++ b/source3/registry/reg_db.c @@ -183,7 +183,7 @@ BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr ) /* allocate some initial memory */ - buffer = malloc(sizeof(pstring)); + buffer = SMB_MALLOC(sizeof(pstring)); buflen = sizeof(pstring); len = 0; @@ -197,7 +197,7 @@ BOOL regdb_store_reg_keys( char *keyname, REGSUBKEY_CTR *ctr ) len += tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) ); if ( len > buflen ) { /* allocate some extra space */ - if ((tmpbuf = Realloc( buffer, len*2 )) == NULL) { + if ((tmpbuf = SMB_REALLOC( buffer, len*2 )) == NULL) { DEBUG(0,("regdb_store_reg_keys: Failed to realloc memory of size [%d]\n", len*2)); ret = False; goto done; diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index a9dfb52f01..1f8c936290 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -154,7 +154,7 @@ BOOL fetch_reg_keys_specific( REGISTRY_KEY *key, char** subkey, uint32 key_index if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) ) return False; - *subkey = strdup( s ); + *subkey = SMB_STRDUP( s ); return True; } diff --git a/source3/registry/reg_objects.c b/source3/registry/reg_objects.c index 9cfeb7faa9..16fb7dd18d 100644 --- a/source3/registry/reg_objects.c +++ b/source3/registry/reg_objects.c @@ -52,16 +52,16 @@ int regsubkey_ctr_addkey( REGSUBKEY_CTR *ctr, const char *keyname ) /* allocate a space for the char* in the array */ if ( ctr->subkeys == 0 ) - ctr->subkeys = talloc( ctr->ctx, sizeof(char*) ); + ctr->subkeys = TALLOC_P( ctr->ctx, char *); else { - pp = talloc_realloc( ctr->ctx, ctr->subkeys, sizeof(char*)*(ctr->num_subkeys+1) ); + pp = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->subkeys, char *, ctr->num_subkeys+1); if ( pp ) ctr->subkeys = pp; } /* allocate the string and save it in the array */ - ctr->subkeys[ctr->num_subkeys] = talloc( ctr->ctx, len+1 ); + ctr->subkeys[ctr->num_subkeys] = TALLOC( ctr->ctx, len+1 ); strncpy( ctr->subkeys[ctr->num_subkeys], keyname, len+1 ); ctr->num_subkeys++; } @@ -138,7 +138,7 @@ REGISTRY_VALUE* dup_registry_value( REGISTRY_VALUE *val ) if ( !val ) return NULL; - if ( !(copy = malloc( sizeof(REGISTRY_VALUE) )) ) { + if ( !(copy = SMB_MALLOC_P( REGISTRY_VALUE)) ) { DEBUG(0,("dup_registry_value: malloc() failed!\n")); return NULL; } @@ -244,22 +244,22 @@ int regval_ctr_addvalue( REGVAL_CTR *ctr, const char *name, uint16 type, /* allocate a slot in the array of pointers */ if ( ctr->num_values == 0 ) - ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) ); + ctr->values = TALLOC_P( ctr->ctx, REGISTRY_VALUE *); else { - ppreg = talloc_realloc( ctr->ctx, ctr->values, sizeof(REGISTRY_VALUE*)*(ctr->num_values+1) ); + ppreg = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->values, REGISTRY_VALUE *, ctr->num_values+1 ); if ( ppreg ) ctr->values = ppreg; } /* allocate a new value and store the pointer in the arrya */ - ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) ); + ctr->values[ctr->num_values] = TALLOC_P( ctr->ctx, REGISTRY_VALUE); /* init the value */ fstrcpy( ctr->values[ctr->num_values]->valuename, name ); ctr->values[ctr->num_values]->type = type; - ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, data_p, size ); + ctr->values[ctr->num_values]->data_p = TALLOC_MEMDUP( ctr->ctx, data_p, size ); ctr->values[ctr->num_values]->size = size; ctr->num_values++; } @@ -280,22 +280,22 @@ int regval_ctr_copyvalue( REGVAL_CTR *ctr, REGISTRY_VALUE *val ) /* allocate a slot in the array of pointers */ if ( ctr->num_values == 0 ) - ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) ); + ctr->values = TALLOC_P( ctr->ctx, REGISTRY_VALUE *); else { - ppreg = talloc_realloc( ctr->ctx, ctr->values, sizeof(REGISTRY_VALUE*)*(ctr->num_values+1) ); + ppreg = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->values, REGISTRY_VALUE *, ctr->num_values+1 ); if ( ppreg ) ctr->values = ppreg; } /* allocate a new value and store the pointer in the arrya */ - ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) ); + ctr->values[ctr->num_values] = TALLOC_P( ctr->ctx, REGISTRY_VALUE); /* init the value */ fstrcpy( ctr->values[ctr->num_values]->valuename, val->valuename ); ctr->values[ctr->num_values]->type = val->type; - ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, val->data_p, val->size ); + ctr->values[ctr->num_values]->data_p = TALLOC_MEMDUP( ctr->ctx, val->data_p, val->size ); ctr->values[ctr->num_values]->size = val->size; ctr->num_values++; } diff --git a/source3/registry/reg_printing.c b/source3/registry/reg_printing.c index 14eb57c6f2..ee4d1dcb64 100644 --- a/source3/registry/reg_printing.c +++ b/source3/registry/reg_printing.c @@ -73,7 +73,7 @@ static char* trim_reg_path( char *path ) p++; if ( *p ) - return strdup(p); + return SMB_STRDUP(p); else return NULL; } @@ -136,7 +136,7 @@ static int print_subpath_environments( char *key, REGSUBKEY_CTR *subkeys ) /* we are dealing with a subkey of "Environments */ - key2 = strdup( key ); + key2 = SMB_STRDUP( key ); keystr = key2; reg_split_path( keystr, &base, &new_path ); @@ -257,7 +257,7 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) /* env */ - key2 = strdup( key ); + key2 = SMB_STRDUP( key ); keystr = key2; reg_split_path( keystr, &base, &new_path ); if ( !base || !new_path ) @@ -322,7 +322,7 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) length = strlen(filename); - buffer2 = Realloc( buffer, buffer_size + (length + 1)*sizeof(uint16) ); + buffer2 = SMB_REALLOC( buffer, buffer_size + (length + 1)*sizeof(uint16) ); if ( !buffer2 ) break; buffer = buffer2; @@ -335,7 +335,7 @@ static int print_subpath_values_environments( char *key, REGVAL_CTR *val ) /* terminated by double NULL. Add the final one here */ - buffer2 = Realloc( buffer, buffer_size + 2 ); + buffer2 = SMB_REALLOC( buffer, buffer_size + 2 ); if ( !buffer2 ) { SAFE_FREE( buffer ); buffer_size = 0; @@ -492,7 +492,7 @@ static int print_subpath_printers( char *key, REGSUBKEY_CTR *subkeys ) /* get information for a specific printer */ - key2 = strdup( key ); + key2 = SMB_STRDUP( key ); keystr = key2; reg_split_path( keystr, &base, &new_path ); @@ -546,7 +546,7 @@ static int print_subpath_values_printers( char *key, REGVAL_CTR *val ) goto done; } - key2 = strdup( key ); + key2 = SMB_STRDUP( key ); keystr = key2; reg_split_path( keystr, &base, &new_path ); -- cgit