From ba48dac3c5fed72968ae7207275898674a4eab3d Mon Sep 17 00:00:00 2001 From: pcg Date: Fri, 13 Feb 2004 13:28:17 +0000 Subject: [PATCH] *** empty log message *** --- Changes | 2 +- src/defaultfont.C | 2 +- src/defaultfont.h | 6 ++---- src/init.C | 5 +++++ src/main.C | 10 ++++++++-- src/rxvt.h | 1 + src/rxvtd.C | 21 ++++++++++++--------- 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Changes b/Changes index 5848e229..54c1ac44 100644 --- a/Changes +++ b/Changes @@ -8,7 +8,7 @@ crashes when you kill your input method (xterm crashes, too). - fix bugs in x flushing, causing an empty screen after startup the first until the first event arives. - - fix ~15kb memleak per term in rxvtd. + - fix various memleaks in rxvtd. 1.8 Mon Feb 2 20:09:18 CET 2004 - almost total conversion to C++. Except for introducing diff --git a/src/defaultfont.C b/src/defaultfont.C index 6835eb91..09d8e288 100644 --- a/src/defaultfont.C +++ b/src/defaultfont.C @@ -430,7 +430,7 @@ rxvt_font_x11::set_properties (rxvt_fontprop &p, const char *name) if (f) { - // the font should really exists now. if not, we have a problem + // the font should really exist now. if not, we have a problem // (e.g. if the user did xset fp rehash just when we were searching fonts). // in that case, just return garbage. bool ret = set_properties (p, f); diff --git a/src/defaultfont.h b/src/defaultfont.h index 5e14c768..c6e917ac 100644 --- a/src/defaultfont.h +++ b/src/defaultfont.h @@ -49,7 +49,7 @@ struct rxvt_font { } rxvt_font () { name = 0; } - ~rxvt_font () { clear (); free (name); }; + ~rxvt_font () { free (name); }; void clear_rect (int x, int y, int w, int h, int color); @@ -65,9 +65,7 @@ struct rxvt_font { int fg, int bg) = 0; }; -//#define FONT_REF(obj) (obj)->refcnt++ -//#define FONT_UNREF(obj) if (!--(obj)->refcnt) delete (obj) -#define FONT_UNREF(f) delete f +#define FONT_UNREF(f) do { (f)->clear (); delete (f); } while (0) struct rxvt_fallback_font; diff --git a/src/init.C b/src/init.C index e7b68c47..42617590 100644 --- a/src/init.C +++ b/src/init.C @@ -764,9 +764,12 @@ rxvt_term::init_env () * @ COLORTERM: terminal sub-name and also indicates its color * @ TERM: terminal name * @ TERMINFO: path to terminfo directory + * @ COLORFGBG: fg;bg color codes */ putenv (env_display); putenv (env_windowid); + if (env_colorfgbg) + putenv (env_colorfgbg); #ifdef RXVT_TERMINFO putenv ("TERMINFO=" RXVT_TERMINFO); @@ -1363,6 +1366,8 @@ rxvt_term::run_command (const char *const *argv) case 0: close (cfd); /* only keep tty_fd and STDERR open */ + init_env (); + if (rxvt_control_tty (tty_fd, ttydev) < 0) rxvt_print_error ("could not obtain control of tty"); else diff --git a/src/main.C b/src/main.C index e771aba2..c3c7e87d 100644 --- a/src/main.C +++ b/src/main.C @@ -110,6 +110,10 @@ rxvt_term::~rxvt_term () scr_release (); + free (env_windowid); + free (env_display); + free (env_term); + free (env_colorfgbg); free (locale); free (codeset); @@ -126,6 +130,9 @@ rxvt_term::~rxvt_term () delete TermWin.fontset; displays.put (display); + + delete envv; + delete argv; } void @@ -286,7 +293,6 @@ rxvt_term::init (int argc, const char *const *argv) XMapWindow (display->display, TermWin.vt); XMapWindow (display->display, TermWin.parent[0]); - init_env (); init_command (cmd_argv); pty_ev.start (cmd_fd, EVENT_READ); @@ -875,8 +881,8 @@ rxvt_term::set_colorfgbg () #endif break; } + sprintf (env_colorfgbg, "COLORFGBG=%s;%s%s", fstr, xpmb, bstr); - putenv (env_colorfgbg); #ifndef NO_BRIGHTCOLOR colorfgbg = DEFAULT_RSTYLE; diff --git a/src/rxvt.h b/src/rxvt.h index 4d8b39c1..51a4e745 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -1059,6 +1059,7 @@ struct rxvt_term : rxvt_vars { unsigned char *v_buffer; /* pointer to physical buffer */ unsigned int v_buflen; /* size of area to write */ char *newfont[MAX_NFONTS]; + stringvec *argv, *envv; /* if != 0, will be freed on destroy time */ #ifdef KEYSYM_RESOURCE const unsigned char *Keysym_map[256]; #endif diff --git a/src/rxvtd.C b/src/rxvtd.C index 66a14ae8..4be63aef 100644 --- a/src/rxvtd.C +++ b/src/rxvtd.C @@ -1,4 +1,5 @@ -#include "rxvtlib.h" +#include "../config.h" +#include "rxvt.h" #include "rxvtdaemon.h" #include "iom.h" @@ -107,8 +108,8 @@ void server::read_cb (io_watcher &w, short revents) { if (!strcmp (tok, "NEW")) { - stringvec argv; - stringvec envv; + stringvec *argv = new stringvec; + stringvec *envv = new stringvec; for (;;) { @@ -118,7 +119,7 @@ void server::read_cb (io_watcher &w, short revents) if (!strcmp (tok, "END")) break; else if (!strcmp (tok, "ENV") && recv (tok)) - envv.push_back (tok.get ()); + envv->push_back (tok.get ()); else if (!strcmp (tok, "CWD") && recv (tok)) { if (chdir (tok)) @@ -126,21 +127,23 @@ void server::read_cb (io_watcher &w, short revents) (char *)tok, strerror (errno)); } else if (!strcmp (tok, "ARG") && recv (tok)) - argv.push_back (tok.get ()); + argv->push_back (tok.get ()); else return err ("protocol error: unexpected NEW token"); } - envv.push_back (0); + envv->push_back (0); { char **old_environ = environ; - environ = envv.begin (); + environ = envv->begin (); - rxvt_init (argv.size (), argv.begin ()); + rxvt_term *term = rxvt_init (argv->size (), argv->begin ()); + + term->argv = argv; + term->envv = envv; environ = old_environ; - envv.clear (); // can't yet save the env 'cause rxvt modifies it : ( } } else -- 2.34.1