diff options
author | Simon Marchi <simon.marchi@ericsson.com> | 2017-11-23 21:56:19 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2017-11-23 21:56:19 -0500 |
commit | 00ea2e2ad34edd202f58d9a1eea2081f0905f9f2 (patch) | |
tree | 5a412c2ee4cf32b2a409559efb215943aa7d997b /gdb | |
parent | 7e8006d14c544a069619dc2bb2c9d2d2b7fd99a6 (diff) | |
download | gdb-00ea2e2ad34edd202f58d9a1eea2081f0905f9f2.zip gdb-00ea2e2ad34edd202f58d9a1eea2081f0905f9f2.tar.gz gdb-00ea2e2ad34edd202f58d9a1eea2081f0905f9f2.tar.bz2 |
Fix memory leak in list_available_thread_groups
Commit
C++ify osdata
479f8de1b3b7e69ca8d557bbe9d843c7d1bc89c5
introduced a memory leak. We allocate std::vectors and insert them in a
map, but never free them. Instead, the map value type can be
std::vector objects directly.
gdb/ChangeLog:
* mi/mi-main.c (list_available_thread_groups): Change map value
type to std::vector.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/mi/mi-main.c | 22 |
2 files changed, 11 insertions, 16 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bb3bf4e..ef19cf4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2017-11-23 Simon Marchi <simon.marchi@ericsson.com> + * mi/mi-main.c (list_available_thread_groups): Change map value + type to std::vector. + +2017-11-23 Simon Marchi <simon.marchi@ericsson.com> + * osdata.c (osdata_end_column, get_osdata): Remove std::move. 2017-11-23 Simon Marchi <simon.marchi@ericsson.com> diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index c7db478..3ca3500 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -716,7 +716,7 @@ list_available_thread_groups (const std::set<int> &ids, int recurse) /* This keeps a map from integer (pid) to vector of struct osdata_item. The vector contains information about all threads for the given pid. */ - std::map<int, std::vector<osdata_item> *> tree_; + std::map<int, std::vector<osdata_item>> tree; /* get_osdata will throw if it cannot return data. */ std::unique_ptr<osdata> data = get_osdata ("processes"); @@ -729,18 +729,8 @@ list_available_thread_groups (const std::set<int> &ids, int recurse) { const std::string *pid = get_osdata_column (item, "pid"); int pid_i = strtoul (pid->c_str (), NULL, 0); - std::vector<osdata_item> *vec; - auto n = tree_.find (pid_i); - if (n == tree_.end ()) - { - vec = new std::vector<osdata_item>; - tree_[pid_i] = vec; - } - else - vec = n->second; - - vec->push_back (item); + tree[pid_i].push_back (item); } } @@ -774,14 +764,14 @@ list_available_thread_groups (const std::set<int> &ids, int recurse) if (recurse) { - auto n = tree_.find (pid_i); - if (n != tree_.end ()) + auto n = tree.find (pid_i); + if (n != tree.end ()) { - std::vector<osdata_item> *children = n->second; + std::vector<osdata_item> &children = n->second; ui_out_emit_list thread_list_emitter (uiout, "threads"); - for (const osdata_item &child : *children) + for (const osdata_item &child : children) { ui_out_emit_tuple tuple_emitter (uiout, NULL); const std::string *tid = get_osdata_column (child, "tid"); |