aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-01-29 23:22:42 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-01-29 23:22:42 -0800
commit316f81119f24471882f2d394cd332bcc1312da4d (patch)
treee040a7a439e5566e3a0518f0cbb092e8a8b788b2
parent8d016040abaa60416dd1e3625b1727dcd84f3e79 (diff)
Excised some more halloc
-rw-r--r--builtin.cpp2
-rw-r--r--builtin.h2
-rw-r--r--complete.cpp14
-rw-r--r--exec.cpp2
-rw-r--r--expand.cpp2
-rw-r--r--kill.cpp11
-rw-r--r--parser.cpp9
-rw-r--r--path.cpp6
-rw-r--r--path.h4
-rw-r--r--proc.h5
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<completion_t> &comp_out,
*/
static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &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<completion_t> &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<completion_t> &co
Should be reasonably fast, since no memory allocations are needed.
*/
- for( i=0; i<al_get_count( &list); i++ )
+ for( int i=0; i<al_get_count( &list); i++ )
{
wchar_t *el = (wchar_t *)al_get( &list, i );
wchar_t *key, *key_end, *val_begin;
@@ -1051,7 +1050,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &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; i<comp.size(); i++ )
+ for( size_t i=0; i<comp.size(); i++ )
{
completion_t &c = comp.at( i );
// const wchar_t *el = c.completion.empty()?NULL:c.completion.c_str();
@@ -1144,8 +1143,7 @@ static void complete_cmd( const wchar_t *cmd,
nxt_path != 0;
nxt_path = wcstok( 0, ARRAY_SEP_STR, &state) )
{
- int prev_count;
- int i;
+ size_t prev_count;
int path_len = wcslen(nxt_path);
int add_slash;
@@ -1169,7 +1167,7 @@ static void complete_cmd( const wchar_t *cmd,
ACCEPT_INCOMPLETE |
EXECUTABLES_ONLY ) != EXPAND_ERROR )
{
- for( i=prev_count; i< comp.size(); i++ )
+ for( size_t i=prev_count; i< comp.size(); i++ )
{
completion_t &c = comp.at( i );
if(c.flags & COMPLETE_NO_CASE )
diff --git a/exec.cpp b/exec.cpp
index 4f86d981..031914d2 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -554,7 +554,7 @@ static void launch_process( process_t *p )
res[i+1] = 0;
p->set_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<wchar_t*>(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 */