aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
authorErwan Velu <erwan.velu@free.fr>2009-11-03 23:07:59 +0100
committerErwan Velu <erwan.velu@free.fr>2009-11-03 23:07:59 +0100
commit0e51af3ebef13ef3255666bfa20a25c4695955fc (patch)
treecf8609941741b7f2f4abf0103312e308ab8ea77f /com32
parent35c507ee84ae948f7b51ba3a8d5062178680d88c (diff)
downloadsyslinux-0e51af3ebef13ef3255666bfa20a25c4695955fc.tar.gz
syslinux-0e51af3ebef13ef3255666bfa20a25c4695955fc.tar.xz
syslinux-0e51af3ebef13ef3255666bfa20a25c4695955fc.zip
hdt: Improving automatic code (memory mgmt)
Impact: Freeing memory We have to be more careful about the malloc & free. We also have to remove spaces around commands
Diffstat (limited to 'com32')
-rw-r--r--com32/hdt/hdt-cli.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index 5f23b2ae..86071942 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -752,21 +752,30 @@ static void reset_prompt()
void start_auto_mode(struct s_hardware *hardware)
{
char *mypch;
- char *temp;
int nb_commands=0;
char *commands[MAX_NB_AUTO_COMMANDS];
- temp=strdup(hardware->auto_label);
- printf("Entering Auto mode\n");
+ printf("Entering Auto mode\n");
+
+ /* Protecting the auto_label from the strtok modifications */
+ char *temp=strdup(hardware->auto_label);
+
+ /* Searching & saving all commands */
mypch = strtok (temp,AUTO_SEPARATOR);
while (mypch != NULL) {
nb_commands++;
- commands[nb_commands]=malloc(AUTO_COMMAND_SIZE);
- sprintf(commands[nb_commands],"%s",mypch);
+ if ((commands[nb_commands]=malloc(AUTO_COMMAND_SIZE)) != NULL)
+ sprintf(commands[nb_commands],"%s",mypch);
mypch = strtok (NULL, AUTO_SEPARATOR);
}
- for (int i=1;i<=nb_commands;i++)
- exec_command(commands[i], hardware);
+
+ /* Executing found commands */
+ for (int i=1;i<=nb_commands;i++) {
+ if (commands[i]) {
+ exec_command(remove_spaces(commands[i]), hardware);
+ free(commands[i]);
+ }
+ }
}
@@ -796,8 +805,6 @@ void start_cli_mode(struct s_hardware *hardware)
/* Start the auto mode if the command line is set*/
if (strlen(hardware->auto_label) > 0) {
start_auto_mode(hardware);
- /* No need to return to cli */
- return;
}
printf("Entering CLI mode\n");