libmysql/libmysql.c

    keep vio from being freed twice when we are low on memory
mysys/safemalloc.c
    changes for --safemalloc-mem-limit
sql/mini_client.cc
    keep vio from being freed twice
sql/mysqld.cc
    changes for --safemalloc-mem-limit
sql/slave.cc
    prevent closing connection twice
sql/sql_string.h
    shrink() did not work right when my_realloc() failed
parent efeec3f2
...@@ -163,3 +163,4 @@ include/.my_sys.h.swp ...@@ -163,3 +163,4 @@ include/.my_sys.h.swp
PENDING/2000-10-25.01 PENDING/2000-10-25.01
PENDING/2000-10-25.02 PENDING/2000-10-25.02
support-files/mysql-3.23.27-beta.spec support-files/mysql-3.23.27-beta.spec
.gdb_history
...@@ -1333,6 +1333,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -1333,6 +1333,7 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (!net->vio || my_net_init(net, net->vio)) if (!net->vio || my_net_init(net, net->vio))
{ {
vio_delete(net->vio); vio_delete(net->vio);
net->vio = 0;
net->last_errno=CR_OUT_OF_MEMORY; net->last_errno=CR_OUT_OF_MEMORY;
strmov(net->last_error,ER(net->last_errno)); strmov(net->last_error,ER(net->last_errno));
goto error; goto error;
......
...@@ -73,6 +73,10 @@ ...@@ -73,6 +73,10 @@
#include "my_static.h" #include "my_static.h"
#include "mysys_err.h" #include "mysys_err.h"
#ifndef DBUG_OFF
ulonglong safemalloc_mem_limit = 0;
#endif
#define pNext tInt._pNext #define pNext tInt._pNext
#define pPrev tInt._pPrev #define pPrev tInt._pPrev
#define sFileName tInt._sFileName #define sFileName tInt._sFileName
...@@ -125,11 +129,18 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags) ...@@ -125,11 +129,18 @@ gptr _mymalloc (uint uSize, const char *sFile, uint uLine, myf MyFlags)
DBUG_ENTER("_mymalloc"); DBUG_ENTER("_mymalloc");
DBUG_PRINT("enter",("Size: %u",uSize)); DBUG_PRINT("enter",("Size: %u",uSize));
if (!sf_malloc_quick) if (!sf_malloc_quick)
(void) _sanity (sFile, uLine); (void) _sanity (sFile, uLine);
/* Allocate the physical memory */ #ifndef DBUG_OFF
pTmp = (struct remember *) malloc ( if(safemalloc_mem_limit &&
uSize + lCurMemory > safemalloc_mem_limit)
pTmp = 0;
else
#endif
/* Allocate the physical memory */
pTmp = (struct remember *) malloc (
sizeof (struct irem) /* remember data */ sizeof (struct irem) /* remember data */
+ sf_malloc_prehunc + sf_malloc_prehunc
+ uSize /* size requested */ + uSize /* size requested */
......
...@@ -611,6 +611,7 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -611,6 +611,7 @@ mc_mysql_connect(MYSQL *mysql,const char *host, const char *user,
if (!net->vio || my_net_init(net, net->vio)) if (!net->vio || my_net_init(net, net->vio))
{ {
vio_delete(net->vio); vio_delete(net->vio);
net->vio = 0; // safety
net->last_errno=CR_OUT_OF_MEMORY; net->last_errno=CR_OUT_OF_MEMORY;
strmov(net->last_error,ER(net->last_errno)); strmov(net->last_error,ER(net->last_errno));
goto error; goto error;
......
...@@ -248,6 +248,10 @@ double log_10[32]; /* 10 potences */ ...@@ -248,6 +248,10 @@ double log_10[32]; /* 10 potences */
I_List<THD> threads,thread_cache; I_List<THD> threads,thread_cache;
time_t start_time; time_t start_time;
#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
extern ulonglong safemalloc_mem_limit;
#endif
pthread_key(MEM_ROOT*,THR_MALLOC); pthread_key(MEM_ROOT*,THR_MALLOC);
pthread_key(THD*, THR_THD); pthread_key(THD*, THR_THD);
pthread_key(NET*, THR_NET); pthread_key(NET*, THR_NET);
...@@ -2228,7 +2232,7 @@ enum options { ...@@ -2228,7 +2232,7 @@ enum options {
OPT_BINLOG_IGNORE_DB, OPT_WANT_CORE, OPT_BINLOG_IGNORE_DB, OPT_WANT_CORE,
OPT_SKIP_CONCURRENT_INSERT, OPT_MEMLOCK, OPT_MYISAM_RECOVER, OPT_SKIP_CONCURRENT_INSERT, OPT_MEMLOCK, OPT_MYISAM_RECOVER,
OPT_REPLICATE_REWRITE_DB, OPT_SERVER_ID, OPT_SKIP_SLAVE_START, OPT_REPLICATE_REWRITE_DB, OPT_SERVER_ID, OPT_SKIP_SLAVE_START,
OPT_SKIP_INNOBASE OPT_SKIP_INNOBASE,OPT_SAFEMALLOC_MEM_LIMIT
}; };
static struct option long_options[] = { static struct option long_options[] = {
...@@ -2284,6 +2288,10 @@ static struct option long_options[] = { ...@@ -2284,6 +2288,10 @@ static struct option long_options[] = {
{"master-info-file", required_argument, 0, (int) OPT_MASTER_INFO_FILE}, {"master-info-file", required_argument, 0, (int) OPT_MASTER_INFO_FILE},
{"myisam-recover", optional_argument, 0, (int) OPT_MYISAM_RECOVER}, {"myisam-recover", optional_argument, 0, (int) OPT_MYISAM_RECOVER},
{"memlock", no_argument, 0, (int) OPT_MEMLOCK}, {"memlock", no_argument, 0, (int) OPT_MEMLOCK},
#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
{"safemalloc-mem-limit", required_argument, 0, (int)
OPT_SAFEMALLOC_MEM_LIMIT},
#endif
{"new", no_argument, 0, 'n'}, {"new", no_argument, 0, 'n'},
{"old-protocol", no_argument, 0, 'o'}, {"old-protocol", no_argument, 0, 'o'},
#ifdef ONE_THREAD #ifdef ONE_THREAD
...@@ -2797,6 +2805,11 @@ static void get_options(int argc,char **argv) ...@@ -2797,6 +2805,11 @@ static void get_options(int argc,char **argv)
case 'P': case 'P':
mysql_port= (unsigned int) atoi(optarg); mysql_port= (unsigned int) atoi(optarg);
break; break;
#if !defined(DBUG_OFF) && defined(SAFEMALLOC)
case OPT_SAFEMALLOC_MEM_LIMIT:
safemalloc_mem_limit = atoi(optarg);
break;
#endif
case OPT_SOCKET: case OPT_SOCKET:
mysql_unix_port= optarg; mysql_unix_port= optarg;
break; break;
......
...@@ -273,7 +273,10 @@ int fetch_nx_table(THD* thd, MASTER_INFO* mi) ...@@ -273,7 +273,10 @@ int fetch_nx_table(THD* thd, MASTER_INFO* mi)
error = 0; error = 0;
err: err:
if(mysql) if(mysql)
mc_mysql_close(mysql); {
mc_mysql_close(mysql);
mysql = 0;
}
if(nx_errno && thd->net.vio) if(nx_errno && thd->net.vio)
send_error(&thd->net, nx_errno, "Error in fetch_nx_table"); send_error(&thd->net, nx_errno, "Error in fetch_nx_table");
...@@ -942,7 +945,10 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused))) ...@@ -942,7 +945,10 @@ pthread_handler_decl(handle_slave,arg __attribute__((unused)))
err: err:
thd->query = thd->db = 0; // extra safety thd->query = thd->db = 0; // extra safety
if(mysql) if(mysql)
mc_mysql_close(mysql); {
mc_mysql_close(mysql);
mysql = 0;
}
thd->proc_info = "waiting for slave mutex on exit"; thd->proc_info = "waiting for slave mutex on exit";
pthread_mutex_lock(&LOCK_slave); pthread_mutex_lock(&LOCK_slave);
slave_running = 0; slave_running = 0;
......
...@@ -125,7 +125,7 @@ public: ...@@ -125,7 +125,7 @@ public:
char *new_ptr; char *new_ptr;
if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0)))) if (!(new_ptr=(char*) my_realloc(Ptr,arg_length,MYF(0))))
{ {
(void) my_free(Ptr,MYF(0)); Alloced_length = 0;
real_alloc(arg_length); real_alloc(arg_length);
} }
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment