What causes `std::bad_alloc` to get thrown in this code?

I’m trying to solve Leetcode Problem 22 (which is just a pretty simple application of recursion), and I was trying to memoize the results in order to speed up computation. However, when I try to store a list of pointers to vectors I run into a std::bad_alloc error, whereas when I simply store a list of pointers the program runs fine. I’m relatively new to C++ and pointers and memory allocation, so this might be a really stupid question, but I’ve been looking at the code for a while and I can’t seem to figure it out.

So, this is the code:

#include <iostream> #include <string> #include <vector>  using namespace std;  class Solution { public:     vector<string> generateParenthesis(int n) {         if (n == 0) {             return {};         }         return generateParenthesis_recursive(n);     }      vector<vector<string>*> memo;     vector<string> generateParenthesis_recursive(unsigned int n) {         if (n < memo.size()) {             return *(memo[n]);         }          vector<string> result;         if (n == 0) {             result = {""};         }         else if (n == 1) {             result = {"()"};         }          else if (n > 1) {             vector<string> left, right;             for (unsigned int k = 0; k < n; k++) {                 left  = generateParenthesis_recursive(k);                 right = generateParenthesis_recursive(n - k - 1);                 for (auto left_parenths : left) {                     for (auto right_parenths : right) {                         result.push_back("(" + left_parenths + ")" + right_parenths);                     }                 }             }         }          while (memo.size() <= n) {             memo.push_back(nullptr);         }         memo[n] = &result;         return result;     } };  int main(int argc, char const *argv[]) {     Solution s;      vector<string> output = s.generateParenthesis(4);     for (auto s : output) {         cout << s << " ";     }     cout << endl;      return 0; } 

I’m not quite sure where, or why, but this throws a std::bad_alloc error. However, changing memo to vector<vector<string>> (and changing other various small parts of the code so that it makes sense), it works fine.

What in particular is causing the error here? There’s no infinite loop, the recursion has a well defined base case, and I don’t think I’m allocating too much memory. I don’t see how the program could be failing to allocate memory.

ODBC Item on MySQL query causes Zabbix server to stop

I’am new to Zabbix. Today I’ve tried to add a SQL item (Database monitoring) to a host without success.

Without this SQL item, the Zabbix server runs fine. I check this with service zabbix-server status.

After I enable the SQL item, hit Check now for it, and run service zabbix-server status again, I’ve got an error:

 zabbix-server.service - Zabbix Server    Loaded: loaded (/lib/systemd/system/zabbix-server.service; disabled; vendor preset: enabled)    Active: active (running) since Fri 2018-11-09 15:41:10 CET; 1s ago   Process: 330 ExecStop=/bin/kill -SIGTERM $  MAINPID (code=exited, status=1/FAILURE)   Process: 335 ExecStart=/usr/sbin/zabbix_server -c $  CONFFILE (code=exited, status=0/SUCCESS)   ... 

You can see that process 330 reports status=1/FAILURE.

After I hit Check now the Zabbix frontend pops up with Request sent successfully. But looking for this item in Monitoring > Latest data there is no value.

The item is configured as:

  • Type: Database monitor
  • Key: db.odbc.select[num-of-events,backend]
  • User name: (empty)
  • Password: (empty)
  • SQL query: select 1;
  • Type of information: Numeric (unsigned)

The ODBC data source backend seems to be working fine:

$   isql backend > +---------------------------------------+ > | Connected!                            | > |                                       | > | sql-statement                         | > | help [tablename]                      | > | quit                                  | > |                                       | > +---------------------------------------+ >  SQL> select 1; > +---------------------+ > | 1                   | > +---------------------+ > | 1                   | > +---------------------+ > SQLRowCount returns 1 > 1 rows fetched 

Here is my ODBC config:

/etc/odbcinst.ini

[mysql] Description = ODBC for MySQL Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8w.so Setup = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc8S.so FileUsage = 1 

/etc/odbc.ini

[ODBC Data Sources] backend  = MySQL unicode backend DSN  [backend] Driver = mysql Decription = Connector/ODBC Driver to Backend DB Server = localhost Port = 3306 User = ??? Password = ??? Database = backend OPTION = 3 SOCKET = /var/run/mysqld/mysqld.sock 

Zabbix is running on Debian Stretch. Zabbix server version is 4.0.1. MySQL version is 10.1.26-MariaDB-0+deb9u1

I’ve took a look into the log with cat zabbix_server.log | grep odbc but the only usefull information is

... 2754:20181109:160050.744 10: /usr/sbin/zabbix_server: poller #2 [got 1 values in 0.000092 sec, getting values](zbx_odbc_connect+0x1ac) [0x55796a7ae97b] ... 

Any idea why the server crashes?

Self-updating form without submit button causes confusion

I’ve made a form that, when a form element changes, a search query is fired and the result is displayed by animating the big number in the middle. For one reason the number doesn’t always change, and for another, users of this app don’t always seem to notice the change, even though the animation of the number ticking up takes 1-2 seconds.

This led to users accidentally hitting the reset button after filling out the form because it was located at the bottom right and was colored gray. Moving the reset button and coloring it red made this work better. Alternatively, one could make an “Update” button at the bottom, but since the form delivers results continuously, it wouldn’t do much.

Are there any other UX tricks that may improve the experience of continuously receiving results? The result isn’t as apparent as when the entire page refreshes with a list of search results, but rather, just an animated number.

One thought is to add an information box when a search query is refined but the result is not updated. Otherwise it seems that the form did not respond. Another thought is some kind of “loading” animation. Another thought is to add an “Update” button, but I don’t know if it should simply trigger the re-animation of the already found result, or display the information box in case the number is the same.

The site is live here in case the screenshot is not tangible enough to review.

Self-updating form without submit button