don't allocate 64K on the stack

This commit is contained in:
Sergei Golubchik 2021-02-18 12:16:11 +01:00
parent e7d9c1d498
commit cbbbdb9c3b

View File

@ -40,11 +40,13 @@ void wsrep_notify_status (wsrep_member_status_t status,
return; return;
} }
char cmd_buf[1 << 16]; // this can be long const long cmd_len = (1 << 16) - 1;
long cmd_len = sizeof(cmd_buf) - 1; char* cmd_ptr = (char*) my_malloc(cmd_len + 1, MYF(MY_WME));
char* cmd_ptr = cmd_buf;
long cmd_off = 0; long cmd_off = 0;
if (!cmd_ptr)
return; // the warning is in the log
cmd_off += snprintf (cmd_ptr + cmd_off, cmd_len - cmd_off, "%s", cmd_off += snprintf (cmd_ptr + cmd_off, cmd_len - cmd_off, "%s",
wsrep_notify_cmd); wsrep_notify_cmd);
@ -93,6 +95,7 @@ void wsrep_notify_status (wsrep_member_status_t status,
{ {
WSREP_ERROR("Notification buffer too short (%ld). Aborting notification.", WSREP_ERROR("Notification buffer too short (%ld). Aborting notification.",
cmd_len); cmd_len);
my_free(cmd_ptr);
return; return;
} }
@ -106,5 +109,6 @@ void wsrep_notify_status (wsrep_member_status_t status,
WSREP_ERROR("Notification command failed: %d (%s): \"%s\"", WSREP_ERROR("Notification command failed: %d (%s): \"%s\"",
err, strerror(err), cmd_ptr); err, strerror(err), cmd_ptr);
} }
my_free(cmd_ptr);
} }