This commit is contained in:
VilhoRaatikka
2014-11-06 18:55:31 +02:00
7 changed files with 35 additions and 26 deletions

View File

@ -34,7 +34,7 @@ int main(int argc, char** argv)
return 1; return 1;
} }
int rd = 0,buffsz = getpagesize(),strsz = 0,ex_val = 0; int rd = 0,buffsz = getpagesize(),strsz = 0,ex_val = 0;
char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char)); char buffer[1024], *strbuff = (char*)calloc(buffsz,sizeof(char));
FILE *input,*expected; FILE *input,*expected;
if(mysql_library_init(num_elements, server_options, server_groups)) if(mysql_library_init(num_elements, server_options, server_groups))
@ -45,25 +45,30 @@ int main(int argc, char** argv)
input = fopen(argv[1],"rb"); input = fopen(argv[1],"rb");
expected = fopen(argv[2],"rb"); expected = fopen(argv[2],"rb");
memset(buffer,0,buffsz);
while((rd = fread(buffer,sizeof(char),buffsz - 1,input))){ while((rd = fread(buffer,sizeof(char),1023,input))){
/**Fill the read buffer*/ /**Fill the read buffer*/
if(strsz + rd >= buffsz){ if(strsz + rd >= buffsz){
char* tmp = (char*)calloc((buffsz*2),sizeof(char));
char* tmp = realloc(strbuff,(buffsz*2)*sizeof(char));
if(!tmp){ if(tmp == NULL){
fprintf(stderr,"Error: Cannot allocate enough memory."); free(strbuff);
fclose(input);
fclose(expected);
mysql_library_end();
fprintf(stderr,"Error: Memory allocation failed.");
return 1; return 1;
} }
memcpy(tmp,strbuff,buffsz);
free(strbuff);
strbuff = tmp; strbuff = tmp;
buffsz *= 2; buffsz *= 2;
} }
memcpy(strbuff+strsz,buffer,rd); memcpy(strbuff+strsz,buffer,rd);
strsz += rd; strsz += rd;
*(strbuff+strsz) = '\0';
char *tok,*nlptr; char *tok,*nlptr;
@ -167,10 +172,10 @@ int main(int argc, char** argv)
gwbuf_free(buff); gwbuf_free(buff);
} }
memset(buffer,0,buffsz);
} }
fclose(input); fclose(input);
fclose(expected); fclose(expected);
mysql_library_end();
free(strbuff); free(strbuff);
return ex_val; return ex_val;
} }

View File

@ -269,7 +269,7 @@ int result = 0;
char *home, buf[1024]; char *home, buf[1024];
/* Unlink any existing password file before running this test */ /* Unlink any existing password file before running this test */
if ((home = getenv("MAXSCALE_HOME")) == NULL) if ((home = getenv("MAXSCALE_HOME")) == NULL || strlen(home) >= 1024)
home = "/usr/local/skysql"; home = "/usr/local/skysql";
sprintf(buf, "%s/etc/passwd", home); sprintf(buf, "%s/etc/passwd", home);
if (strcmp(buf, "/etc/passwd") != 0) if (strcmp(buf, "/etc/passwd") != 0)

View File

@ -158,6 +158,7 @@ static bool do_hashtest(
hashtable_free(h); hashtable_free(h);
return_succp: return_succp:
free(val_arr);
return succp; return succp;
} }

View File

@ -46,7 +46,9 @@ HINT *hint;
/* Hint tests */ /* Hint tests */
ss_dfprintf(stderr, ss_dfprintf(stderr,
"testhint : Add a parameter hint to a null list"); "testhint : Add a parameter hint to a null list");
hint = hint_create_parameter(NULL, strdup("name"), "value"); char* name = strdup("name");
hint = hint_create_parameter(NULL, name, "value");
free(name);
ss_info_dassert(NULL != hint, "New hint list should not be null"); ss_info_dassert(NULL != hint, "New hint list should not be null");
ss_info_dassert(0 == strcmp("value", hint->value), "Hint value should be correct"); ss_info_dassert(0 == strcmp("value", hint->value), "Hint value should be correct");
ss_info_dassert(0 != hint_exists(&hint, HINT_PARAMETER), "Hint of parameter type should exist"); ss_info_dassert(0 != hint_exists(&hint, HINT_PARAMETER), "Hint of parameter type should exist");

View File

@ -68,7 +68,8 @@ char *status;
server_set_status(server, SERVER_MASTER); server_set_status(server, SERVER_MASTER);
status = server_status(server); status = server_status(server);
ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status."); ss_info_dassert(0 == strcmp("Master, Running", status), "Should find correct status.");
server_clear_status(server, SERVER_MASTER); server_clear_status(server, SERVER_MASTER);
free(status);
status = server_status(server); status = server_status(server);
ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared."); ss_info_dassert(0 == strcmp("Running", status), "Status of Server should be Running after master status cleared.");
if (NULL != status) free(status); if (NULL != status) free(status);
@ -78,7 +79,6 @@ char *status;
ss_dfprintf(stderr, "\t..done\nFreeing Server."); ss_dfprintf(stderr, "\t..done\nFreeing Server.");
ss_info_dassert(0 != server_free(server), "Free should succeed"); ss_info_dassert(0 != server_free(server), "Free should succeed");
ss_dfprintf(stderr, "\t..done\n"); ss_dfprintf(stderr, "\t..done\n");
return 0; return 0;
} }

View File

@ -303,18 +303,19 @@ int load_query()
int i, qcount = 0, qbuff_sz = 10, rval = 0; int i, qcount = 0, qbuff_sz = 10, rval = 0;
int offset = 0; int offset = 0;
unsigned int qlen = 0; unsigned int qlen = 0;
buffer = (char*)malloc(4092*sizeof(char));
if((buffer = malloc(4092*sizeof(char))) == NULL){ if(buffer == NULL){
printf("Error: cannot allocate enough memory.\n"); printf("Error: cannot allocate enough memory.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n"); skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
return 1; return 1;
} }
if((query_list = calloc(qbuff_sz,sizeof(char*))) == NULL){ query_list = calloc(qbuff_sz,sizeof(char*));
if(query_list == NULL){
printf("Error: cannot allocate enough memory.\n"); printf("Error: cannot allocate enough memory.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n"); skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
rval = 1; free(buffer);
goto retblock; return 1;
} }
@ -953,6 +954,7 @@ int process_opts(int argc, char** argv)
instance.verbose = 1; instance.verbose = 1;
if(argc < 2){ if(argc < 2){
close(fd);
return 1; return 1;
} }
char* conf_name = NULL; char* conf_name = NULL;
@ -970,6 +972,9 @@ int process_opts(int argc, char** argv)
break; break;
case 'c': case 'c':
if(conf_name){
free(conf_name);
}
conf_name = strdup(optarg); conf_name = strdup(optarg);
break; break;

View File

@ -1525,15 +1525,12 @@ skygw_query_type_t is_read_tmp_table(
} }
} }
if(tsize > 0) for(i = 0; i<tsize;i++)
{ {
for(i = 0; i<tsize;i++) free(tbl[i]);
{
free(tbl[i]);
}
free(tbl);
} }
free(tbl);
return qtype; return qtype;
} }
@ -1542,7 +1539,6 @@ skygw_query_type_t is_read_tmp_table(
* the database and table name, create a hashvalue and * the database and table name, create a hashvalue and
* add it to the router client session's property. If property * add it to the router client session's property. If property
* doesn't exist then create it first. * doesn't exist then create it first.
*
* @param instance Router instance * @param instance Router instance
* @param router_session Router client session * @param router_session Router client session
* @param querybuf GWBUF containing the query * @param querybuf GWBUF containing the query