summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-05-24 11:47:25 +0200
committerJim Meyering <meyering@redhat.com>2011-05-25 16:20:10 +0200
commit5a634c3834b189ccafe0ba62caae3534c86994cc (patch)
tree564a767db6ed3e8b937bad9a1c49775547683f9d
parentaa85679b9affab4f15b45a8f719d6e002f06f8c3 (diff)
downloadpatch-5a634c3834b189ccafe0ba62caae3534c86994cc.tar.gz
plug a leak in bestmatch
* src/bestmatch.h (bestmatch): Don't leak V when returning early.
-rw-r--r--src/bestmatch.h9
1 files 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;
}