Browse Source

Fix memory leaks for dyn views

Serj Kalichev 11 years ago
parent
commit
05db649ab0
4 changed files with 17 additions and 19 deletions
  1. 3 2
      clish/command/command.c
  2. 3 2
      clish/shell/shell_execute.c
  3. 4 6
      clish/shell/shell_startup.c
  4. 7 9
      clish/view/view.c

+ 3 - 2
clish/command/command.c

@@ -58,10 +58,11 @@ static void clish_command_fini(clish_command_t * this)
 	/* finalize each of the parameter instances */
 	clish_paramv_delete(this->paramv);
 
-	lub_string_free(this->alias);
-	lub_string_free(this->viewid);
 	clish_action_delete(this->action);
 	clish_config_delete(this->config);
+	lub_string_free(this->alias);
+	lub_string_free(this->viewname);
+	lub_string_free(this->viewid);
 	lub_string_free(this->detail);
 	lub_string_free(this->escape_chars);
 	lub_string_free(this->regex_chars);

+ 3 - 2
clish/shell/shell_execute.c

@@ -166,10 +166,11 @@ int clish_shell_execute(clish_context_t *context, char **out)
 
 	/* Move into the new view */
 	if (!result) {
-		const char *viewname = clish_shell_expand(clish_command__get_viewname(cmd), SHELL_VAR_NONE, context);
+		char *viewname = clish_shell_expand(clish_command__get_viewname(cmd), SHELL_VAR_NONE, context);
 		if (viewname) {
 			/* Search for the view */
-			clish_view_t *view = clish_shell_find_create_view(this, viewname, NULL);
+			clish_view_t *view = clish_shell_find_view(this, viewname);
+			lub_string_free(viewname);
 			/* Save the PWD */
 			if (view) {
 				char *line = clish_shell__get_line(context);

+ 4 - 6
clish/shell/shell_startup.c

@@ -41,17 +41,15 @@ int clish_shell_startup(clish_shell_t *this)
 }
 
 /*----------------------------------------------------------- */
-void clish_shell__set_startup_view(clish_shell_t * this, const char * viewname)
+void clish_shell__set_startup_view(clish_shell_t *this, const char *viewname)
 {
-	clish_view_t *view;
-
 	assert(this);
 	assert(this->startup);
 	clish_command__force_viewname(this->startup, viewname);
 }
 
 /*----------------------------------------------------------- */
-void clish_shell__set_startup_viewid(clish_shell_t * this, const char * viewid)
+void clish_shell__set_startup_viewid(clish_shell_t *this, const char *viewid)
 {
 	assert(this);
 	assert(this->startup);
@@ -59,7 +57,7 @@ void clish_shell__set_startup_viewid(clish_shell_t * this, const char * viewid)
 }
 
 /*----------------------------------------------------------- */
-void clish_shell__set_default_shebang(clish_shell_t * this, const char * shebang)
+void clish_shell__set_default_shebang(clish_shell_t *this, const char *shebang)
 {
 	assert(this);
 	lub_string_free(this->default_shebang);
@@ -67,7 +65,7 @@ void clish_shell__set_default_shebang(clish_shell_t * this, const char * shebang
 }
 
 /*----------------------------------------------------------- */
-const char * clish_shell__get_default_shebang(const clish_shell_t * this)
+const char * clish_shell__get_default_shebang(const clish_shell_t *this)
 {
 	assert(this);
 	return this->default_shebang;

+ 7 - 9
clish/view/view.c

@@ -75,24 +75,22 @@ static void clish_view_fini(clish_view_t * this)
 		clish_command_delete(cmd);
 	}
 
-	/* free our memory */
-	lub_string_free(this->name);
-	this->name = NULL;
-	lub_string_free(this->prompt);
-	this->prompt = NULL;
-
 	/* finalize each of the namespace instances */
 	for (i = 0; i < this->nspacec; i++) {
 		clish_nspace_delete(this->nspacev[i]);
 	}
 
-	/* Free hotkey structures */
-	clish_hotkeyv_delete(this->hotkeys);
-
 	/* free the namespace vector */
 	free(this->nspacev);
 	this->nspacec = 0;
 	this->nspacev = NULL;
+
+	/* Free hotkey structures */
+	clish_hotkeyv_delete(this->hotkeys);
+
+	/* free our memory */
+	lub_string_free(this->name);
+	lub_string_free(this->prompt);
 }
 
 /*---------------------------------------------------------