Commit 253b69ff authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #1032

stop using variable sized arrays off of stack on main line

git-svn-id: file:///svn/mysql/tokudb-engine/src@7991 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3e6933d9
...@@ -3647,9 +3647,14 @@ static int create_sub_table(const char *table_name, int flags) { ...@@ -3647,9 +3647,14 @@ static int create_sub_table(const char *table_name, int flags) {
} }
static int mkdirpath(char *name, mode_t mode) { static int mkdirpath(char *name, mode_t mode) {
char* parent = NULL;
int r = mkdir(name, mode); int r = mkdir(name, mode);
if (r == -1 && errno == ENOENT) { if (r == -1 && errno == ENOENT) {
char parent[strlen(name)+1]; parent = (char *)my_malloc(strlen(name)+1,MYF(MY_WME));
if (parent == NULL) {
r = ENOMEM;
goto cleanup;
}
strcpy(parent, name); strcpy(parent, name);
char *cp = strrchr(parent, '/'); char *cp = strrchr(parent, '/');
if (cp) { if (cp) {
...@@ -3659,20 +3664,24 @@ static int mkdirpath(char *name, mode_t mode) { ...@@ -3659,20 +3664,24 @@ static int mkdirpath(char *name, mode_t mode) {
r = mkdir(name, mode); r = mkdir(name, mode);
} }
} }
cleanup:
my_free(parent, MYF(MY_ALLOW_ZERO_PTR));
return r; return r;
} }
#include <dirent.h> #include <dirent.h>
static int rmall(const char *dname) { static int rmall(const char *dname) {
int error = 0; int error = 0;
DIR *d = opendir(dname); DIR *d = opendir(dname);
char* fname = NULL;
if (d) { if (d) {
struct dirent *dirent; struct dirent *dirent;
while ((dirent = readdir(d)) != 0) { while ((dirent = readdir(d)) != 0) {
if (0 == strcmp(dirent->d_name, ".") || 0 == strcmp(dirent->d_name, "..")) if (0 == strcmp(dirent->d_name, ".") || 0 == strcmp(dirent->d_name, ".."))
continue; continue;
char fname[strlen(dname) + 1 + strlen(dirent->d_name) + 1]; fname = (char *)my_malloc(strlen(dname) + 1 + strlen(dirent->d_name) + 1, MYF(MY_WME));
sprintf(fname, "%s/%s", dname, dirent->d_name); sprintf(fname, "%s/%s", dname, dirent->d_name);
if (dirent->d_type == DT_DIR) { if (dirent->d_type == DT_DIR) {
error = rmall(fname); error = rmall(fname);
...@@ -3713,6 +3722,8 @@ static int rmall(const char *dname) { ...@@ -3713,6 +3722,8 @@ static int rmall(const char *dname) {
break; break;
} }
} }
my_free(fname, MYF(MY_ALLOW_ZERO_PTR));
fname = NULL;
} }
} }
closedir(d); closedir(d);
......
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