Control: reassign -1 src:libtextwrap Control: tag -1 + patch Hi, On Mon, Apr 27, 2015 at 07:24:21AM +0200, Christian PERRIER wrote: > Quoting Niels Thykier (niels@thykier.net): > > > Hi, > > > > Thanks for the report. > > > > A quick scan with cppcheck highlighted several cases of memory leaks. > > Please see attached diff for a quick (untested) attempt of plugging these. > > > > Thanks, > > ~Niels > > > > Committed and pushed to master. Untested as well and not sure it > really fixes the leak(s) spotted by Guo Yixuan but it can't indeed > hurt. Thank you for the help! After debugging with mtrace(), I located some memory leak in libtextwrap. A patch is attached. It appears to fix the problem in my case. Cheers, Yixuan
--- a/textwrap.c
+++ b/textwrap.c
@@ -256,6 +256,7 @@ textwrap(const textwrap_t *prop, const c
/* locale initialization */
encoding = normalize(nl_langinfo(CODESET));
encoding_type = set_encoding_type(encoding);
+ free(encoding);
/* buffer initialization */
len = strlen(text);
@@ -295,6 +296,7 @@ textwrap(const textwrap_t *prop, const c
if (!*p) {
stringt_addstringt(out, word);
+ stringt_destroy(word);
return stringt_destroy_extract(out);
}
@@ -306,6 +308,7 @@ textwrap(const textwrap_t *prop, const c
* memory for out
*/
stringt_addstr(out, " <ERR>");
+ stringt_destroy(word);
return stringt_destroy_extract(out);
}
w = mbwidth(p, ml);
@@ -319,7 +322,10 @@ textwrap(const textwrap_t *prop, const c
if (*now == '\n') {
stringt_addstringt(out, word);
stringt_addstr(out, "\n");
- if (!*p) return stringt_destroy_extract(out);
+ if (!*p) {
+ stringt_destroy(word);
+ return stringt_destroy_extract(out);
+ }
stringt_addstr(out, head2); line_width = head2_width;
stringt_zero(word); word_width = 0;
continue;
@@ -334,7 +340,10 @@ textwrap(const textwrap_t *prop, const c
/* new line */
stringt_addstringt(out, word);
stringt_addstr(out, "\n");
- if (!*p) return stringt_destroy_extract(out);
+ if (!*p) {
+ stringt_destroy(word);
+ return stringt_destroy_extract(out);
+ }
stringt_addstr(out, head2); line_width = head2_width;
stringt_zero(word); word_width = 0;
} else {
Attachment:
signature.asc
Description: Digital signature