From 316f81119f24471882f2d394cd332bcc1312da4d Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 29 Jan 2012 23:22:42 -0800 Subject: Excised some more halloc --- builtin.cpp | 2 +- builtin.h | 2 +- complete.cpp | 14 ++++++-------- exec.cpp | 2 +- expand.cpp | 2 +- kill.cpp | 11 +++++------ parser.cpp | 9 ++++----- path.cpp | 6 +++--- path.h | 4 ++-- proc.h | 5 +++-- 10 files changed, 27 insertions(+), 30 deletions(-) diff --git a/builtin.cpp b/builtin.cpp index fd3f7779..cca47249 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -3810,7 +3810,7 @@ void builtin_destroy() hash_destroy( &builtin ); } -int builtin_exists( wchar_t *cmd ) +int builtin_exists( const wchar_t *cmd ) { CHECK( cmd, 0 ); diff --git a/builtin.h b/builtin.h index 5ad27bf8..d35aecea 100644 --- a/builtin.h +++ b/builtin.h @@ -123,7 +123,7 @@ void builtin_destroy(); /** Is there a builtin command with the given name? */ -int builtin_exists( wchar_t *cmd ); +int builtin_exists( const wchar_t *cmd ); /** Execute a builtin command diff --git a/complete.cpp b/complete.cpp index ff523ee8..b75b940a 100644 --- a/complete.cpp +++ b/complete.cpp @@ -607,7 +607,7 @@ static void parse_cmd_string( void *context, wchar_t *cmd, *path; /* Get the path of the command */ - path = path_get_path( context, str ); + path = (wchar_t *)halloc_register(context, path_get_path( str )); if( path == 0 ) { /** @@ -937,7 +937,6 @@ static void complete_strings( std::vector &comp_out, */ static void complete_cmd_desc( const wchar_t *cmd, std::vector &comp ) { - int i; const wchar_t *cmd_start; int cmd_len; wchar_t *lookup_cmd=0; @@ -973,7 +972,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector &co skip = 1; - for( i=0; i< comp.size(); i++ ) + for( size_t i=0; i< comp.size(); i++ ) { const completion_t &c = comp.at ( i ); @@ -1017,7 +1016,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector &co Should be reasonably fast, since no memory allocations are needed. */ - for( i=0; i &co This needs to do a reallocation for every description added, but there shouldn't be that many completions, so it should be ok. */ - for( i=0; iset_argv(res); - p->actual_cmd = sh_command; + p->actual_cmd = wcsdup(sh_command); res_real = wcsv2strv( (const wchar_t **) res); diff --git a/expand.cpp b/expand.cpp index 29d71865..cd678d8a 100644 --- a/expand.cpp +++ b/expand.cpp @@ -723,7 +723,7 @@ static int expand_pid( wchar_t *in, } } - int prev = out.size(); + size_t prev = out.size(); if( !find_process( in+1, flags, out ) ) return 0; diff --git a/kill.cpp b/kill.cpp index 3cc94796..4f7b5bb7 100644 --- a/kill.cpp +++ b/kill.cpp @@ -52,15 +52,14 @@ static int has_xsel() { static int called=0; static int res = 0; - + if (!called) { - void *context = halloc(0, 0); - wchar_t *path = path_get_path( context, L"xsel" ); + wchar_t *path = path_get_path( L"xsel" ); res = !!path; - halloc_free( context ); + free(path); called = 1; -} - + } + return res; } diff --git a/parser.cpp b/parser.cpp index d7c847bf..f1c80317 100644 --- a/parser.cpp +++ b/parser.cpp @@ -1884,7 +1884,7 @@ int parser_t::parse_job( process_t *p, if( !p->type ) { if( use_builtin && - builtin_exists( const_cast(args->at(0).completion.c_str()) ) ) + builtin_exists(args->at(0).completion.c_str())) { p->type = INTERNAL_BUILTIN; is_new_block |= parser_keywords_is_block( args->at( 0 ).completion.c_str() ); @@ -1899,19 +1899,18 @@ int parser_t::parse_job( process_t *p, */ if( current_block->skip ) { - p->actual_cmd = L""; + p->actual_cmd = wcsdup(L""); } else { int err; - - p->actual_cmd = path_get_path( j, args->at(0).completion.c_str() ); + p->actual_cmd = path_get_path( args->at(0).completion.c_str() ); err = errno; /* Check if the specified command exists */ - if( p->actual_cmd == 0 ) + if( p->actual_cmd == NULL ) { /* diff --git a/path.cpp b/path.cpp index 53c4274d..be38eaa8 100644 --- a/path.cpp +++ b/path.cpp @@ -128,7 +128,7 @@ bool path_get_path_string(const wcstring &cmd_str, wcstring &output, const env_v } -wchar_t *path_get_path( void *context, const wchar_t *cmd ) +wchar_t *path_get_path( const wchar_t *cmd ) { int err = ENOENT; @@ -147,7 +147,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) } if( S_ISREG(buff.st_mode) ) - return halloc_wcsdup( context, cmd ); + return wcsdup( cmd ); else { errno = EACCES; @@ -180,7 +180,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd ) /* Allocate string long enough to hold the whole command */ - wchar_t *new_cmd = (wchar_t *)halloc( context, sizeof(wchar_t)*(wcslen(cmd)+path.size()+2) ); + wchar_t *new_cmd = (wchar_t *)calloc(wcslen(cmd)+path.size()+2, sizeof(wchar_t) ); /* We tokenize a copy of the path, since strtok modifies diff --git a/path.h b/path.h index 465fca2d..9994199a 100644 --- a/path.h +++ b/path.h @@ -28,9 +28,9 @@ wchar_t *path_get_config( void *context); \param cmd The name of the executable. \param context the halloc context to use for memory allocations - \return 0 if the command can not be found, the path of the command otherwise. + \return 0 if the command can not be found, the path of the command otherwise. The result should be freed with free(). */ -wchar_t *path_get_path( void *context, const wchar_t *cmd ); +wchar_t *path_get_path( const wchar_t *cmd ); class env_vars; bool path_get_path_string(const wcstring &cmd, wcstring &output, const env_vars &vars); diff --git a/proc.h b/proc.h index b8ba3b11..ef9ea3ab 100644 --- a/proc.h +++ b/proc.h @@ -166,6 +166,7 @@ class process_t if (this->next != NULL) delete this->next; this->free_argv(); + free((void *)actual_cmd); //may be NULL } /** @@ -178,7 +179,6 @@ class process_t /** Sets argv */ void set_argv(wchar_t **argv) { - free_argv(); #if 0 // argv must be a malloc'd array of malloc'd strings. This bit of nonsense below can help catch if someone doesn't pass us something from malloc. @@ -191,6 +191,7 @@ class process_t } #endif + free_argv(); this->argv_array = argv; } @@ -203,7 +204,7 @@ class process_t /** Returns argv[idx] */ const wchar_t *argv(size_t idx) const { return argv_array[idx]; } - /** actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC */ + /** actual command to pass to exec in case of EXTERNAL or INTERNAL_EXEC. malloc'd! */ const wchar_t *actual_cmd; /** process ID */ -- cgit v1.2.3