From 5a634c3834b189ccafe0ba62caae3534c86994cc Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 24 May 2011 11:47:25 +0200 Subject: plug a leak in bestmatch * src/bestmatch.h (bestmatch): Don't leak V when returning early. --- src/bestmatch.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bestmatch.h b/src/bestmatch.h index 958b1ca..1c91e16 100644 --- a/src/bestmatch.h +++ b/src/bestmatch.h @@ -36,7 +36,7 @@ * * Returns the number of changes (insertions and deletions) required to get * from a[] to b[]. Returns MAX + 1 if a[] cannot be turned into b[] with - * MAX or fewer changes. + * MAX or fewer changes, in which case *PY is not modified. * * MIN specifies the minimum number of elements in which a[] and b[] must * match. This allows to prevent trivial matches in which a sequence is @@ -89,7 +89,10 @@ bestmatch(OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, fmid_plus_2_min = fmid + 2 * min; min += yoff; if (min > ylim) - return max + 1; + { + c = max + 1; + goto free_and_return; + } } else fmid_plus_2_min = 0; /* disable this check */ @@ -153,6 +156,8 @@ bestmatch(OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, done: if (py) *py = ymax; + + free_and_return: free (V); return c; } -- cgit v1.2.1