aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-01-23 09:40:03 +1000
committerGravatar axel <axel@liljencrantz.se>2006-01-23 09:40:03 +1000
commit58761f82e7719c97125c8f9851327f1b4a5eb8d0 (patch)
tree4062ce24a1e324ded00cacc60235927864e0ad2d
parent0ccc657aa6ad410fd047dc88cdb302252edb5ebf (diff)
Avoid memory leaks in the complete builtin on errors
darcs-hash:20060122234003-ac50b-6b1b63d1b8fc9b8cfc7aa64b49db386618718d78.gz
-rw-r--r--builtin_complete.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/builtin_complete.c b/builtin_complete.c
index 005dab66..e9c0669b 100644
--- a/builtin_complete.c
+++ b/builtin_complete.c
@@ -21,6 +21,11 @@ Functions used for implementing the complete builtin.
#include "parser.h"
#include "translate.h"
+/*
+ builtin_complete_* are a set of rather silly looping functions that
+ make sure that all the proper combinations of complete_add or
+ complete_remove get called.
+*/
static void builtin_complete_add2( const wchar_t *cmd,
int cmd_type,
@@ -232,7 +237,7 @@ static void builtin_complete_remove( array_list_t *cmd,
int builtin_complete( wchar_t **argv )
{
-
+ int res=0;
int argc=0;
int result_mode=SHARED;
int remove = 0;
@@ -255,7 +260,7 @@ int builtin_complete( wchar_t **argv )
woptind=0;
- while( 1 )
+ while( res == 0 )
{
const static struct woption
long_options[] =
@@ -345,8 +350,8 @@ int builtin_complete( wchar_t **argv )
// builtin_print_help( argv[0], sb_err );
- return 1;
-
+ res = 1;
+ break;
case 'x':
result_mode |= EXCLUSIVE;
@@ -410,13 +415,17 @@ int builtin_complete( wchar_t **argv )
case '?':
// builtin_print_help( argv[0], sb_err );
- return 1;
+ res = 1;
+ break;
}
}
-
- if( woptind != argc )
+
+ if( res != 0 )
+ {
+ }
+ else if( woptind != argc )
{
sb_printf( sb_err,
_( L"%ls: Too many arguments\n" ),
@@ -425,17 +434,13 @@ int builtin_complete( wchar_t **argv )
parser_current_line() );
// builtin_print_help( argv[0], sb_err );
- return 1;
+ res = 1;
}
-
- if( load )
+ else if( load )
{
complete_load( load, 1 );
- return 0;
}
-
-
- if( (al_get_count( &cmd) == 0 ) && (al_get_count( &path) == 0 ) )
+ else if( (al_get_count( &cmd) == 0 ) && (al_get_count( &path) == 0 ) )
{
/* No arguments specified, meaning we print the definitions of
* all specified completions to stdout.*/
@@ -466,6 +471,7 @@ int builtin_complete( wchar_t **argv )
}
}
+
al_foreach( &cmd, (void (*)(const void *))&free );
al_foreach( &path, (void (*)(const void *))&free );
@@ -474,7 +480,6 @@ int builtin_complete( wchar_t **argv )
sb_destroy( &short_opt );
al_destroy( &gnu_opt );
al_destroy( &old_opt );
-
- return 0;
+ return res;
}