utf8: release strbuf on error return in strbuf_utf8_replace()

Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Rene Scharfe committed Aug 30, 2017 at 20:20 UTC 9a012bf32a3b21648ab96f2bd234a563c22e0ae7
1 file changed +2 -1
utf8.c
+2 -1
@@ -381,7 +381,7 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
381 old = src;
382 n = utf8_width((const char**)&src, NULL);
383 if (!src) /* broken utf-8, do nothing */
384 - return;
384 + goto out;
385 if (n && w >= pos && w < pos + width) {
386 if (subst) {
387 memcpy(dst, subst, subst_len);
@@ -397,6 +397,7 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
397 }
398 strbuf_setlen(&sb_dst, dst - sb_dst.buf);
399 strbuf_swap(sb_src, &sb_dst);
400 +out:
401 strbuf_release(&sb_dst);
402 }
403