Skip to content

Commit

Permalink
Fix memory leak in case of early return
Browse files Browse the repository at this point in the history
Closes GH-7.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
alessiosavi authored and wooorm committed Aug 12, 2019
1 parent 4f90034 commit 8727fcc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion levenshtein.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// See <https://en.wikipedia.org/wiki/Levenshtein_distance> for more information.
size_t
levenshtein_n(const char *a, const size_t length, const char *b, const size_t bLength) {
size_t *cache = calloc(length, sizeof(size_t));

size_t index = 0;
size_t bIndex = 0;
size_t distance;
Expand All @@ -30,6 +30,7 @@ levenshtein_n(const char *a, const size_t length, const char *b, const size_t bL
if (bLength == 0) {
return length;
}
size_t *cache = calloc(length, sizeof(size_t));

// initialize the vector.
while (index < length) {
Expand Down

0 comments on commit 8727fcc

Please sign in to comment.