aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-25 20:28:52 +0100
committerSebastiano Tronto <sebastiano.tronto@gmail.com>2021-11-25 20:28:52 +0100
commit679fac1f8be87ccb431d1ce981e98bdbfbd61dd8 (patch)
tree21aa433f8491bdf88820cfa4722a2f91a09e8730 /src
parent3bc44cb7ee1f27d1e0183b82be6ba6b9c05e837c (diff)
downloadnissy-679fac1f8be87ccb431d1ce981e98bdbfbd61dd8.tar.gz
nissy-679fac1f8be87ccb431d1ce981e98bdbfbd61dd8.zip
Fixed a bug in freeing memory after execution of certain commands (thanks to Tommaso for reporting)
Diffstat (limited to '')
-rw-r--r--src/commands.c38
-rw-r--r--src/commands.h1
2 files changed, 23 insertions, 16 deletions
diff --git a/src/commands.c b/src/commands.c
index 48f5eba..2442d81 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -105,13 +105,7 @@ solve_parse_args(int c, char **v)
105 int i; 105 int i;
106 long val; 106 long val;
107 107
108 CommandArgs *a = malloc(sizeof(CommandArgs)); 108 CommandArgs *a = new_args();
109
110 a->success = false;
111 a->opts = malloc(sizeof(SolveOptions));
112 a->step = steps[0];
113 a->command = NULL;
114 a->scramble = NULL;
115 109
116 a->opts->min_moves = 0; 110 a->opts->min_moves = 0;
117 a->opts->max_moves = 20; 111 a->opts->max_moves = 20;
@@ -182,12 +176,7 @@ CommandArgs *
182help_parse_args(int c, char **v) 176help_parse_args(int c, char **v)
183{ 177{
184 int i; 178 int i;
185 CommandArgs *a = malloc(sizeof(CommandArgs)); 179 CommandArgs *a = new_args();
186
187 a->scramble = NULL;
188 a->opts = NULL;
189 a->step = NULL;
190 a->command = NULL;
191 180
192 if (c == 1) { 181 if (c == 1) {
193 for (i = 0; i < NCOMMANDS; i++) 182 for (i = 0; i < NCOMMANDS; i++)
@@ -205,9 +194,9 @@ help_parse_args(int c, char **v)
205CommandArgs * 194CommandArgs *
206parse_no_arg(int c, char **v) 195parse_no_arg(int c, char **v)
207{ 196{
208 CommandArgs *a = malloc(sizeof(CommandArgs)); 197 CommandArgs *a = new_args();
209 198
210 a->success = true; 199 a->success = true;
211 200
212 return a; 201 return a;
213} 202}
@@ -215,9 +204,10 @@ parse_no_arg(int c, char **v)
215CommandArgs * 204CommandArgs *
216print_parse_args(int c, char **v) 205print_parse_args(int c, char **v)
217{ 206{
218 CommandArgs *a = malloc(sizeof(CommandArgs)); 207 CommandArgs *a = new_args();
219 208
220 a->success = read_scramble(c, v, a); 209 a->success = read_scramble(c, v, a);
210
221 return a; 211 return a;
222} 212}
223 213
@@ -364,3 +354,19 @@ free_args(CommandArgs *args)
364 354
365 free(args); 355 free(args);
366} 356}
357
358CommandArgs *
359new_args()
360{
361 CommandArgs *args = malloc(sizeof(CommandArgs));
362
363 args->success = false;
364 args->scramble = NULL; /* initialized in read_scramble */
365 args->opts = malloc(sizeof(SolveOptions));
366
367 /* step and command are static */
368 args->step = NULL;
369 args->command = NULL;
370
371 return args;
372}
diff --git a/src/commands.h b/src/commands.h
index f2703fa..938a0bd 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -7,6 +7,7 @@
7#define NCOMMANDS 10 7#define NCOMMANDS 10
8 8
9void free_args(CommandArgs *args); 9void free_args(CommandArgs *args);
10CommandArgs * new_args();
10 11
11extern Command * commands[NCOMMANDS]; 12extern Command * commands[NCOMMANDS];
12 13

Generated with cgit - Back to sebastiano.tronto.net