On Sun, Nov 22, 2009 at 06:52:27AM +0100, Werner LEMBERG wrote: > > Now I don't know groff/troff so I ask you, is this not excessive? > > I would like to understand why troff uses so much memory. > > It's a bug, fixed on 2009-04-10, I think. Please try the CVS version. > Using it, the maximum number of allocated heap space (as checked with > massif) is 10.52MB for the above call on my Linux box.
Thanks for that pointer, it was very helpful. I've tried the current version from CVS, but it uses (certain) statem objects after they have been freed and later frees them again. It looks like an ownership problem. Nodes delete their statem objects when they are destroyed, but the same statem objects are deleted when they are popped from the state machine stack. The attached patch solves the above problem and also fixes all "definitely lost" memleaks reported by valgrind. With that patch groff uses about 10MB on my system as well. Regards, Maurice. -- Maurice van der Pot Gentoo Linux Developer griffo...@gentoo.org http://www.gentoo.org Gnome Planner Developer griffo...@kfk4ever.com http://live.gnome.org/Planner
Index: src/roff/troff/env.cpp =================================================================== RCS file: /sources/groff/groff/src/roff/troff/env.cpp,v retrieving revision 1.22 diff -u -B -r1.22 env.cpp --- src/roff/troff/env.cpp 5 Jan 2009 20:11:12 -0000 1.22 +++ src/roff/troff/env.cpp 22 Nov 2009 13:16:30 -0000 @@ -2213,14 +2213,15 @@ */ if (curdiv == topdiv && topdiv->before_first_page) topdiv->begin_page(); - macro *m = new macro; - m->append_str("devtag:"); + + macro m; + m.append_str("devtag:"); for (const char *p = nm; *p; p++) if (!invalid_input_char((unsigned char)*p)) - m->append(*p); - m->append(' '); - m->append_int(i); - return new special_node(*m); + m.append(*p); + m.append(' '); + m.append_int(i); + return new special_node(m); } return 0; } Index: src/roff/troff/input.cpp =================================================================== RCS file: /sources/groff/groff/src/roff/troff/input.cpp,v retrieving revision 1.60 diff -u -B -r1.60 input.cpp --- src/roff/troff/input.cpp 7 May 2009 16:22:17 -0000 1.60 +++ src/roff/troff/input.cpp 22 Nov 2009 13:16:33 -0000 @@ -531,6 +531,8 @@ { if (t->is_diversion) { div_level--; + if (diversion_state) + delete diversion_state; diversion_state = t->diversion_state; } } @@ -4398,6 +4400,7 @@ args += c; if (i != limit) args += ' '; + delete p; } if (limit > 0) { args += '\0'; @@ -4419,6 +4422,7 @@ args += '"'; if (i != limit) args += ' '; + delete p; } if (limit > 0) { args += '\0'; @@ -4438,6 +4442,7 @@ } if (input_stack::space_follows_arg(i)) args += ' '; + delete p; } if (limit > 0) { args += '\0'; Index: src/roff/troff/mtsm.cpp =================================================================== RCS file: /sources/groff/groff/src/roff/troff/mtsm.cpp,v retrieving revision 1.6 diff -u -B -r1.6 mtsm.cpp --- src/roff/troff/mtsm.cpp 5 Jan 2009 20:11:12 -0000 1.6 +++ src/roff/troff/mtsm.cpp 22 Nov 2009 13:16:33 -0000 @@ -390,8 +390,6 @@ #endif if (sp == 0) fatal("empty state machine stack"); - if (sp->state) - delete sp->state; sp->state = 0; stack *t = sp; sp = sp->next;
pgpJWwS3DQ2vv.pgp
Description: PGP signature