Skip to content

Commit 031572f

Browse files
committed
Copy over note about memory leaks in test code
The lab proper had a nice paragraph on the need to sometimes find and fix memory leaks in test code, and I decided that should probably be here as well.
1 parent 7f5d382 commit 031572f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ the `main()` method or even testing code. So carefully trace the uses
183183
until you get to someplace where you know the memory will never be
184184
used again, and that's where you'd insert the necessary `free()` call.
185185

186+
:bangbang: One non-obvious, but important, place to look for memory leaks is
187+
in the test code. If the test code calls some function `f()` that returns an
188+
array or string that is allocated somewhere in `f` (or a function `f` calls),
189+
then that memory is lost if the test code doesn't free up that returned array.
190+
So if `valgrind` says there's a leak where some memory is allocated in a
191+
function and then returned to the test code, then the fix is
192+
_in the test code_. In general we don't encourage you to fiddle with the
193+
test code (you could always just change the test code to say everything
194+
passes!), but if the memory leaks to the test code, then that's where the
195+
fix has to be made.
196+
186197
## What to do
187198

188199
- [ ] Compile the program `check_whitespace.c`

0 commit comments

Comments
 (0)