From f37420cee267a1283a2a642bb99982971b89258f Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Fri, 26 Jun 2015 16:37:04 -0400 Subject: [PATCH] Validate frequency being deallocated Don't add Freq to Free if it wasn't actually in Allocated. Alternatively, could be stricter and fail rather than silently ignoring. --- chapter5/frequency.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chapter5/frequency.erl b/chapter5/frequency.erl index 9cea6a6..0a7ddef 100755 --- a/chapter5/frequency.erl +++ b/chapter5/frequency.erl @@ -67,4 +67,8 @@ allocate({[Freq|Free], Allocated}, Pid) -> deallocate({Free, Allocated}, Freq) -> NewAllocated=lists:keydelete(Freq, 1, Allocated), - {[Freq|Free], NewAllocated}. + case NewAllocated of + Allocated -> {Free, Allocated}; + _ -> {[Freq|Free], NewAllocated} + end. +