Skip to content

Commit cfc62cd

Browse files
committed
cleanup
1 parent 13b0ef7 commit cfc62cd

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

phpdbg_cmd.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_D
123123
char *p, *s;
124124
char b[PHPDBG_MAX_CMD];
125125
int l=0;
126-
enum states {
127-
IN_BETWEEN,
126+
enum states {
127+
IN_BETWEEN,
128128
IN_WORD,
129129
IN_STRING
130130
} state = IN_BETWEEN;
@@ -134,11 +134,14 @@ static inline phpdbg_input_t** phpdbg_read_argv(char *buffer, int *argc TSRMLS_D
134134
(*argc) = 0;
135135

136136
#define RESET_STATE() do {\
137-
phpdbg_input_t *next = emalloc(sizeof(phpdbg_input_t));\
138-
if (next) {\
137+
phpdbg_input_t *arg = emalloc(sizeof(phpdbg_input_t));\
138+
if (arg) {\
139139
b[l]=0;\
140-
next->string = estrndup(b, l);\
141-
argv[(*argc)++] = next;\
140+
arg->string = estrndup(b, l);\
141+
arg->argv=NULL;\
142+
arg->argc=0;\
143+
argv = (phpdbg_input_t**) erealloc(argv, sizeof(phpdbg_input_t*) * ((*argc)+1));\
144+
argv[(*argc)++] = arg;\
142145
l=0;\
143146
}\
144147
state = IN_BETWEEN;\
@@ -283,6 +286,30 @@ phpdbg_input_t* phpdbg_read_input(TSRMLS_D) /* {{{ */
283286
return NULL;
284287
} /* }}} */
285288

289+
void phpdbg_destroy_input(phpdbg_input_t **input TSRMLS_DC) /*{{{ */
290+
{
291+
if (*input) {
292+
293+
if ((*input)->string) {
294+
efree((*input)->string);
295+
}
296+
297+
if ((*input)->argc > 0) {
298+
int arg;
299+
for (arg=0; arg<(*input)->argc; arg++) {
300+
phpdbg_destroy_input(
301+
&(*input)->argv[arg] TSRMLS_CC);
302+
}
303+
}
304+
305+
if ((*input)->argv) {
306+
efree((*input)->argv);
307+
}
308+
309+
efree(*input);
310+
}
311+
} /* }}} */
312+
286313
int phpdbg_do_cmd(const phpdbg_command_t *command, char *cmd_line, size_t cmd_len TSRMLS_DC) /* {{{ */
287314
{
288315
int rc = FAILURE;

phpdbg_prompt.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
993993
}
994994
}
995995

996-
if (input->string) {
997-
efree(input->string);
998-
}
999-
efree(input);
1000-
996+
phpdbg_destroy_input(&input TSRMLS_CC);
1001997
} while ((input = phpdbg_read_input(TSRMLS_C)) && (input->length > 0L));
1002998

1003999
if (!input->length)
@@ -1013,12 +1009,7 @@ int phpdbg_interactive(TSRMLS_D) /* {{{ */
10131009
}
10141010

10151011
out:
1016-
if (input) {
1017-
if (input->string) {
1018-
efree(input->string);
1019-
}
1020-
efree(input);
1021-
}
1012+
phpdbg_destroy_input(&input TSRMLS_CC);
10221013

10231014
return ret;
10241015
} /* }}} */

0 commit comments

Comments
 (0)