Commits

Steven! Ragnarök committed 629d60e

Clean up parser error causing random segfaults during GC.

Comments (0)

Files changed (1)

 	arg_list->children = head;
 	arg_node = parse_arg();
 	tail->node = arg_node;
-	strip_head();
+	tail->next = NULL;
+
+	if (arg_node != NULL) {
+		strip_head();
+	}
 
 	arg_node = parse_arg();
-	strip_head();
+	if (arg_node != NULL) {
+		strip_head();
+	}
 
 	while (arg_node != NULL) {
 		tail->next = malloc(sizeof(ast_nodelist));
 		tail->node = arg_node;
 		tail->next = NULL;
 		arg_node = parse_arg();
-		strip_head();
+		if (arg_node != NULL) {
+			strip_head();
+		}
 	}
 	return arg_list;
 }
 	arg = parse_arg();
 	strip_head();
 	
+	redirect = malloc(sizeof(ast_node));
+	redirect->children = malloc(sizeof(ast_nodelist));
+	redirect->children->node = arg;
+	redirect->children->next = NULL;
+
 	switch (redirect_type) {
 		case 4:
 			redirect->type = STDIN_REDIRECT;
 			break;
 	}
 
-	redirect->children = malloc(sizeof(ast_nodelist));
-	redirect->children->node = arg;
-	redirect->children->next = NULL;
 	return redirect;
 }
 
 
 ast_node *parse_value() {
 	ast_node *value = malloc(sizeof(ast_node));
+	value->children = NULL;
 	value->type = VALUE;
 	strncpy(value->token, tokens->str, MAX_TOKEN_LENGTH);
 	return value;
 	int i, varlen = strlen(tokens->str);
 	ast_node *variable = malloc(sizeof(ast_node));
 	variable->type = VARIABLE;
+	variable->children = NULL;
 	for (i = 0; i < varlen; i++) {
 		variable->token[i] = tokens->str[i + 1];
 	}