ModSim: assignment 2.7 does not free() all rabbits.

parent d167a381
CC=clang CC=clang
CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE CFLAGS=-Wall -Wextra -pedantic -std=c99 -D_GNU_SOURCE -g
LFLAGS=-lm LFLAGS=-lm
all: q1 q2 q3 q4 q5 q7 all: q1 q2 q3 q4 q5 q7
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
typedef struct rabbit { typedef struct rabbit {
int age; int age;
...@@ -20,6 +21,7 @@ rabbit *rabbit_born() { ...@@ -20,6 +21,7 @@ rabbit *rabbit_born() {
rabbits->prev = r; rabbits->prev = r;
r->age = 0; r->age = 0;
r->prev = NULL;
rabbits = r; rabbits = r;
rabbit_count++; rabbit_count++;
...@@ -67,6 +69,7 @@ void sequence(int generations, int max_age) { ...@@ -67,6 +69,7 @@ void sequence(int generations, int max_age) {
puts(""); puts("");
// This does not free() all rabbits
while( rabbits ) while( rabbits )
rabbit_die(&rabbits); rabbit_die(&rabbits);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment