From 14cf09c12ab4108777767d627e264d021f5e8515 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Fri, 25 Sep 2009 11:47:15 +0200 Subject: [PATCH] Bug #47645: Segmentation fault when out of memory during handlerton initialization There is a missing check for memory allocation failure when allocating memory for the handlerton structure. If the handlerton init function tries to de-reference the pointer, it will cause a segmentation fault and crash the server. This patch fixes the problem by not calling the init function if memory allocation failed, and instead prints an informative error message and reports the error to the caller. --- sql/handler.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sql/handler.cc b/sql/handler.cc index e5c64452aaf..f966a9099ee 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -430,6 +430,14 @@ int ha_initialize_handlerton(st_plugin_int *plugin) hton= (handlerton *)my_malloc(sizeof(handlerton), MYF(MY_WME | MY_ZEROFILL)); + + if (hton == NULL) + { + sql_print_error("Unable to allocate memory for plugin '%s' handlerton.", + plugin->name.str); + goto err_no_hton_memory; + } + /* Historical Requirement */ plugin->data= hton; // shortcut for the future if (plugin->plugin->init && plugin->plugin->init(hton)) @@ -540,6 +548,7 @@ err_deinit: err: my_free((uchar*) hton, MYF(0)); +err_no_hton_memory: plugin->data= NULL; DBUG_RETURN(1); }