From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id BD0BF3858436; Mon, 13 Feb 2023 14:51:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD0BF3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676299885; bh=crtdeTyJJX6rWAVShg4B3NBkWnWSuM626PrGGj1kPOQ=; h=From:To:Subject:Date:From; b=N5AzNOgFcXxRZW3Dngt0aOAnXJS0ce+C4EYRr7q+KY1z6NfYUhoEbrTBc30uLDqa7 TxS3e0XWPgG4Hb/tDigYLORw38ckrFkd7tDcSW19MwOobrPMaK8hksMy1hWBYdlF8Y D3dyj8fSKmk3MvfkFxPx2KCr1321SmdYJ/ot4zo8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/tui: don't leak the known_window_types map X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 9ae4519da9026cf1748a7e78783847de530de488 X-Git-Newrev: d27ff777c65654bc4166165cc45743fcc7bae3a0 Message-Id: <20230213145125.BD0BF3858436@sourceware.org> Date: Mon, 13 Feb 2023 14:51:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dd27ff777c656= 54bc4166165cc45743fcc7bae3a0 commit d27ff777c65654bc4166165cc45743fcc7bae3a0 Author: Andrew Burgess Date: Thu Jan 12 16:18:53 2023 +0000 gdb/tui: don't leak the known_window_types map =20 This commit finishes the task that was started in the previous commit. =20 Now that all Python TUI window factories are correctly deleted when the Python interpreter is shut down, we no longer need to dynamically allocate the known_window_types map in tui-layout.c =20 This commit changes known_window_types to a statically allocated data structure, removes the dynamic allocation from initialize_known_windows, and then replaces lots of '->' with '.' throughout this file. =20 There should be no user visible changes after this commit. =20 Reviewed-By: Tom Tromey Diff: --- gdb/tui/tui-layout.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index ba7ec89973e..bb8356c5544 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -343,22 +343,17 @@ make_standard_window (const char *) return tui_win_list[V]; } =20 -/* A map holding all the known window types, keyed by name. Note that - this is heap-allocated and "leaked" at gdb exit. This avoids - ordering issues with destroying elements in the map at shutdown. - In particular, destroying this map can occur after Python has been - shut down, causing crashes if any window destruction requires - running Python code. */ +/* A map holding all the known window types, keyed by name. */ =20 -static window_types_map *known_window_types; +static window_types_map known_window_types; =20 /* See tui-layout.h. */ =20 known_window_names_range all_known_window_names () { - auto begin =3D known_window_names_iterator (known_window_types->begin ()= ); - auto end =3D known_window_names_iterator (known_window_types->end ()); + auto begin =3D known_window_names_iterator (known_window_types.begin ()); + auto end =3D known_window_names_iterator (known_window_types.end ()); return known_window_names_range (begin, end); } =20 @@ -371,8 +366,8 @@ tui_get_window_by_name (const std::string &name) if (name =3D=3D window->name ()) return window; =20 - auto iter =3D known_window_types->find (name); - if (iter =3D=3D known_window_types->end ()) + auto iter =3D known_window_types.find (name); + if (iter =3D=3D known_window_types.end ()) error (_("Unknown window type \"%s\""), name.c_str ()); =20 tui_win_info *result =3D iter->second (name.c_str ()); @@ -386,20 +381,18 @@ tui_get_window_by_name (const std::string &name) static void initialize_known_windows () { - known_window_types =3D new window_types_map; - - known_window_types->emplace (SRC_NAME, + known_window_types.emplace (SRC_NAME, make_standard_window); - known_window_types->emplace (CMD_NAME, + known_window_types.emplace (CMD_NAME, make_standard_window); - known_window_types->emplace (DATA_NAME, + known_window_types.emplace (DATA_NAME, make_standard_window); - known_window_types->emplace (DISASSEM_NAME, + known_window_types.emplace (DISASSEM_NAME, make_standard_window); - known_window_types->emplace (STATUS_NAME, + known_window_types.emplace (STATUS_NAME, make_standard_window); } @@ -431,11 +424,11 @@ tui_register_window (const char *name, window_factory= &&factory) this far then NAME must be a user defined window. Remove any existing factory and replace it with this new version. */ =20 - auto iter =3D known_window_types->find (name); - if (iter !=3D known_window_types->end ()) - known_window_types->erase (iter); + auto iter =3D known_window_types.find (name); + if (iter !=3D known_window_types.end ()) + known_window_types.erase (iter); =20 - known_window_types->emplace (std::move (name_copy), + known_window_types.emplace (std::move (name_copy), std::move (factory)); } =20 @@ -1216,8 +1209,8 @@ initialize_layouts () static bool validate_window_name (const std::string &name) { - auto iter =3D known_window_types->find (name); - return iter !=3D known_window_types->end (); + auto iter =3D known_window_types.find (name); + return iter !=3D known_window_types.end (); } =20 /* Implementation of the "tui new-layout" command. */