From b2099ee728addd34b0497bcddcc0fcd6a2503f0b Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 20 Oct 2011 21:35:59 +0000 Subject: [PATCH] * fhandler.h (fhandler*::copyto): Free path_conv strings first. * path.h (cfree_and_null): Rename and expand from cfree_maybe. (path_conv &operator =): Call free_strings rather than freeing strings directly. --- winsup/cygwin/fhandler.h | 32 ++++++++++++++++++++++++++++++++ winsup/cygwin/path.h | 17 +++++++++++++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 58ca7b1e1..7d583bd42 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -430,6 +430,7 @@ public: virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -596,6 +597,7 @@ class fhandler_socket: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -649,6 +651,7 @@ public: virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -694,6 +697,7 @@ public: void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -743,6 +747,7 @@ public: void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -771,6 +776,7 @@ class fhandler_mailslot : public fhandler_base_overlapped void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -819,6 +825,7 @@ class fhandler_dev_raw: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -878,6 +885,7 @@ class fhandler_dev_floppy: public fhandler_dev_raw void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -925,6 +933,7 @@ class fhandler_dev_tape: public fhandler_dev_raw void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -990,6 +999,7 @@ class fhandler_disk_file: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1027,6 +1037,7 @@ class fhandler_cygdrive: public fhandler_disk_file void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1090,6 +1101,7 @@ class fhandler_serial: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1154,6 +1166,7 @@ class fhandler_termios: public fhandler_base virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1352,6 +1365,7 @@ private: void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1394,6 +1408,7 @@ class fhandler_pty_common: public fhandler_termios virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1447,6 +1462,7 @@ class fhandler_pty_slave: public fhandler_pty_common void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1504,6 +1520,7 @@ public: void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1530,6 +1547,7 @@ class fhandler_dev_null: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1564,6 +1582,7 @@ class fhandler_dev_zero: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1601,6 +1620,7 @@ class fhandler_dev_random: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1640,6 +1660,7 @@ class fhandler_dev_mem: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1675,6 +1696,7 @@ class fhandler_dev_clipboard: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1713,6 +1735,7 @@ class fhandler_windows: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1759,6 +1782,7 @@ class fhandler_dev_dsp: public fhandler_base void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1809,6 +1833,7 @@ class fhandler_virtual : public fhandler_base virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1840,6 +1865,7 @@ class fhandler_proc: public fhandler_virtual virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1875,6 +1901,7 @@ class fhandler_procsys: public fhandler_virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1903,6 +1930,7 @@ class fhandler_procsysvipc: public fhandler_proc void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1932,6 +1960,7 @@ class fhandler_netdrive: public fhandler_virtual void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -1971,6 +2000,7 @@ class fhandler_registry: public fhandler_proc void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -2002,6 +2032,7 @@ class fhandler_process: public fhandler_proc void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } @@ -2030,6 +2061,7 @@ class fhandler_procnet: public fhandler_proc void copyto (fhandler_base *x) { + x->pc.free_strings (); *reinterpret_cast (x) = *this; x->reset (this); } diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index 3a9c08ca4..f390156cc 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -282,12 +282,21 @@ class path_conv PWCHAR get_wide_win32_path (PWCHAR wc); operator DWORD &() {return fileattr;} operator int () {return fileattr; } -# define cfree_maybe(x) if (x) cfree ((void *) (x)) +# define cfree_and_null(x) \ + if (x) \ + { \ + cfree ((void *) (x)); \ + (x) = NULL; \ + } + void free_strings () + { + cfree_and_null (path); + cfree_and_null (normalized_path); + cfree_and_null (wide_path); + } path_conv &operator =(const path_conv& pc) { - cfree_maybe (path); - cfree_maybe (normalized_path); - cfree_maybe (wide_path); + free_strings (); memcpy (this, &pc, sizeof pc); path = cstrdup (pc.path); conv_handle.dup (pc.conv_handle);