mirror of
https://github.com/samba-team/samba.git
synced 2025-08-04 08:22:08 +03:00
r26453: Janitorial: Don't use a static char[] in smb_readline_replacement.
Fix up callers to free the memory returned, as that is needed if we use the
original readline function as well.
(This used to be commit c81ead1c38
)
This commit is contained in:
committed by
Stefan Metzmacher
parent
d8feba9faf
commit
43ac3d9b44
@ -2997,16 +2997,18 @@ static int process_stdin(struct smbclient_context *ctx)
|
|||||||
char *the_prompt = talloc_asprintf(ctx, "smb: %s> ", ctx->remote_cur_dir);
|
char *the_prompt = talloc_asprintf(ctx, "smb: %s> ", ctx->remote_cur_dir);
|
||||||
char *cline = smb_readline(the_prompt, readline_callback, completion_fn);
|
char *cline = smb_readline(the_prompt, readline_callback, completion_fn);
|
||||||
talloc_free(the_prompt);
|
talloc_free(the_prompt);
|
||||||
|
|
||||||
if (!cline) break;
|
if (!cline) break;
|
||||||
|
|
||||||
/* special case - first char is ! */
|
/* special case - first char is ! */
|
||||||
if (*cline == '!') {
|
if (*cline == '!') {
|
||||||
system(cline + 1);
|
system(cline + 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc |= process_command_string(ctx, cline);
|
rc |= process_command_string(ctx, cline);
|
||||||
|
free(cline);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -546,12 +546,16 @@ int main(int argc, char **argv)
|
|||||||
via readline :-( */
|
via readline :-( */
|
||||||
line = smb_readline(prompt, NULL, reg_completion);
|
line = smb_readline(prompt, NULL, reg_completion);
|
||||||
|
|
||||||
if (line == NULL)
|
if (line == NULL) {
|
||||||
|
free(prompt);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (line[0] != '\n') {
|
if (line[0] != '\n') {
|
||||||
ret = W_ERROR_IS_OK(process_cmd(ctx, line));
|
ret = W_ERROR_IS_OK(process_cmd(ctx, line));
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
|
free(prompt);
|
||||||
}
|
}
|
||||||
talloc_free(ctx);
|
talloc_free(ctx);
|
||||||
|
|
||||||
|
@ -77,13 +77,18 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
|
|||||||
char **(completion_fn)(const char *text, int start, int end))
|
char **(completion_fn)(const char *text, int start, int end))
|
||||||
{
|
{
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
static char line[1024];
|
char *line;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
int fd = STDIN_FILENO;
|
int fd = STDIN_FILENO;
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
do_debug("%s", prompt);
|
do_debug("%s", prompt);
|
||||||
|
|
||||||
|
line = (char *)malloc(BUFSIZ);
|
||||||
|
if (!line) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
timeout.tv_sec = 5;
|
timeout.tv_sec = 5;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
@ -92,7 +97,7 @@ static char *smb_readline_replacement(const char *prompt, void (*callback)(void)
|
|||||||
FD_SET(fd,&fds);
|
FD_SET(fd,&fds);
|
||||||
|
|
||||||
if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) {
|
if (sys_select_intr(fd+1,&fds,NULL,NULL,&timeout) == 1) {
|
||||||
ret = x_fgets(line, sizeof(line), x_stdin);
|
ret = x_fgets(line, BUFSIZ, x_stdin);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (callback)
|
if (callback)
|
||||||
|
@ -824,6 +824,7 @@ static bool test_SetAliasInfo(struct dcerpc_pipe *p, struct torture_context *tct
|
|||||||
case ALIASINFONAME: init_lsa_String(&r.in.info->name,TEST_ALIASNAME); break;
|
case ALIASINFONAME: init_lsa_String(&r.in.info->name,TEST_ALIASNAME); break;
|
||||||
case ALIASINFODESCRIPTION: init_lsa_String(&r.in.info->description,
|
case ALIASINFODESCRIPTION: init_lsa_String(&r.in.info->description,
|
||||||
"Test Description, should test I18N as well"); break;
|
"Test Description, should test I18N as well"); break;
|
||||||
|
case ALIASINFOALL: printf("ALIASINFOALL ignored\n"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = dcerpc_samr_SetAliasInfo(p, tctx, &r);
|
status = dcerpc_samr_SetAliasInfo(p, tctx, &r);
|
||||||
|
@ -500,6 +500,7 @@ void run_shell(struct torture_context *tctx)
|
|||||||
run_test(tctx, argv[1]);
|
run_test(tctx, argv[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(cline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user