Skip to content

Commit

Permalink
Fix several problems revealed by static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
wangbin579 committed May 21, 2018
1 parent 5f3a73c commit b3501eb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
1 change: 0 additions & 1 deletion plugins/shard/shard-plugin.c
Expand Up @@ -2069,7 +2069,6 @@ network_mysqld_shard_plugin_free(chassis *chas, chassis_plugin_config *config)
g_free(config->address);
}
sql_filter_vars_destroy();
g_debug("%s: call shard_conf_destroy", G_STRLOC);
shard_conf_destroy();

g_free(config);
Expand Down
1 change: 0 additions & 1 deletion src/mysql-proxy-cli.c
Expand Up @@ -623,7 +623,6 @@ release_resouces_when_exit(struct chassis_frontend_t *frontend, chassis *srv, GE
g_debug("%s: call chassis_options_free", G_STRLOC);
if (opts)
chassis_options_free(opts);
g_debug("%s: call g_hash_table_destroy", G_STRLOC);
g_debug("%s: call chassis_log_free", G_STRLOC);
chassis_log_free(log);
tc_log_end();
Expand Down
12 changes: 9 additions & 3 deletions src/sharding-config.c
Expand Up @@ -455,9 +455,15 @@ shard_conf_destroy(void)
if (shard_conf_vdbs) {
g_list_free_full(shard_conf_vdbs, (GDestroyNotify) sharding_vdb_free);
}
g_hash_table_destroy(shard_conf_tables);
g_list_free_full(shard_conf_single_tables, (GDestroyNotify) single_table_free);
g_list_free_full(shard_conf_all_groups, g_string_true_free);
if (shard_conf_tables) {
g_hash_table_destroy(shard_conf_tables);
}
if (shard_conf_single_tables) {
g_list_free_full(shard_conf_single_tables, (GDestroyNotify) single_table_free);
}
if (shard_conf_all_groups) {
g_list_free_full(shard_conf_all_groups, g_string_true_free);
}
}

static GHashTable *load_shard_from_json(gchar *json_str);
Expand Down
17 changes: 13 additions & 4 deletions tools/lemon.c
Expand Up @@ -2785,6 +2785,7 @@ void Parse(struct lemon *gp)
filebuf = (char *)malloc( filesize+1);
if (filesize>100000000 || filebuf == 0) {
ErrorMsg(ps.filename,0,"Input file too large.");
free(filebuf);
gp->errorcnt++;
fclose(fp);
return;
Expand Down Expand Up @@ -3278,8 +3279,8 @@ PRIVATE char *pathsearch(char *argv0, char *name, int modemask)
if (pathlist == 0) pathlist = ".:/bin:/usr/bin";
pathbuf = (char *) malloc( lemonStrlen(pathlist) + 1);
path = (char *)malloc( lemonStrlen(pathlist)+lemonStrlen(name)+2);
pathbufptr = pathbuf;
if ((pathbuf != 0) && (path!=0) ) {
pathbufptr = pathbuf;
lemon_strcpy(pathbuf, pathlist);
while(*pathbuf) {
cp = strchr(pathbuf,':');
Expand All @@ -3292,7 +3293,10 @@ PRIVATE char *pathsearch(char *argv0, char *name, int modemask)
else pathbuf = &cp[1];
if (access(path,modemask) == 0) break;
}
free(pathbufptr);
}

if (pathbufptr) {
free(pathbufptr);
}
}
return path;
Expand Down Expand Up @@ -3356,7 +3360,7 @@ PRIVATE FILE *tplt_open(struct lemon *lemp)
static char templatename[] = "lempar.c";
char buf[1000];
FILE *in;
char *tpltname;
char *tpltname, *tmp = NULL;
char *cp;

/* first, see if user specified a template filename on the command line. */
Expand Down Expand Up @@ -3388,7 +3392,8 @@ PRIVATE FILE *tplt_open(struct lemon *lemp)
} else if (access(templatename,004) == 0) {
tpltname = templatename;
} else{
tpltname = pathsearch(lemp->argv0,templatename,0);
tmp = pathsearch(lemp->argv0,templatename,0);
tpltname = tmp;
}
if (tpltname == 0) {
fprintf(stderr,"Can't find the parser driver template file \"%s\".\n",
Expand All @@ -3397,6 +3402,9 @@ PRIVATE FILE *tplt_open(struct lemon *lemp)
return 0;
}
in = fopen(tpltname,"rb");
if (tmp) {
free(tmp);
}
if (in == 0) {
fprintf(stderr,"Can't open the template file \"%s\".\n",templatename);
lemp->errorcnt++;
Expand Down Expand Up @@ -4492,6 +4500,7 @@ void ReportTable(
/* Append any addition code the user desires */
tplt_print(out,lemp,lemp->extracode,&lineno);

free(pActtab);
fclose(in);
fclose(out);
return;
Expand Down

0 comments on commit b3501eb

Please sign in to comment.