Browse Source

Free the ptype's regexp only if the pattern is set.

git-svn-id: https://klish.googlecode.com/svn/trunk@285 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
d389ed2501
2 changed files with 22 additions and 24 deletions
  1. 4 2
      clish/param/param.c
  2. 18 22
      clish/ptype/ptype.c

+ 4 - 2
clish/param/param.c

@@ -170,8 +170,10 @@ void clish_param_help(const clish_param_t * this, size_t offset)
 
 	if (CLISH_PARAM_SUBCOMMAND == clish_param__get_mode(this))
 		name = clish_param__get_value(this);
-	else
-		name = clish_ptype__get_text(this->ptype);
+	else {
+		if (!(name = clish_ptype__get_text(this->ptype)))
+			name = clish_ptype__get_name(this->ptype);
+	}
 
 	fprintf(stderr, "%s %*c%s",
 		name, (int)(offset - strlen(name)), ' ', this->text);

+ 18 - 22
clish/ptype/ptype.c

@@ -487,6 +487,24 @@ clish_ptype_t *clish_ptype_new(const char *name,
 /*--------------------------------------------------------- */
 static void clish_ptype_fini(clish_ptype_t * this)
 {
+	if (this->pattern) {
+		switch (this->method) {
+		/*------------------------------------------------- */
+		case CLISH_PTYPE_REGEXP:
+			regfree(&this->u.regexp);
+			break;
+		/*------------------------------------------------- */
+		case CLISH_PTYPE_INTEGER:
+		case CLISH_PTYPE_UNSIGNEDINTEGER:
+			break;
+		/*------------------------------------------------- */
+		case CLISH_PTYPE_SELECT:
+			lub_argv_delete(this->u.select.items);
+			break;
+		/*------------------------------------------------- */
+		}
+	}
+
 	lub_string_free(this->name);
 	this->name = NULL;
 	lub_string_free(this->text);
@@ -495,28 +513,6 @@ static void clish_ptype_fini(clish_ptype_t * this)
 	this->pattern = NULL;
 	lub_string_free(this->range);
 	this->range = NULL;
-
-	switch (this->method) {
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_REGEXP:
-		{
-			regfree(&this->u.regexp);
-			break;
-		}
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_INTEGER:
-	case CLISH_PTYPE_UNSIGNEDINTEGER:
-		{
-			break;
-		}
-	/*------------------------------------------------- */
-	case CLISH_PTYPE_SELECT:
-		{
-			lub_argv_delete(this->u.select.items);
-			break;
-		}
-	/*------------------------------------------------- */
-	}
 }
 
 /*--------------------------------------------------------- */