提交 32c7d43c 编写于 作者: Z Zhangxiaoyu 提交者: lifeng68

fix memory leak

Signed-off-by: NZhangxiaoyu <zhangxiaoyu58@huawei.com>
上级 d280970e
......@@ -69,12 +69,13 @@ source $basepath/install_depends.sh
echo_success "===================RUN DT-LLT TESTCASES START========================="
cd $ISULAD_COPY_PATH
sed -i 's/fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO/fd == 0 || fd == 1 || fd == 2 || fd >= 1000/g' ./src/utils/cutils/utils.c
rm -rf build
mkdir build && cd build
if [[ "x${GCOV}" == "xON" ]]; then
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON -DENABLE_UT=ON ..
make -j $(nproc)
ctest # && ctest -T memcheck
ctest -T memcheck --output-on-failure
if [[ $? -ne 0 ]]; then
exit 1
fi
......@@ -84,7 +85,7 @@ if [[ "x${GCOV}" == "xON" ]]; then
else
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_UT=ON ..
make -j $(nproc)
ctest
ctest -D ExperimentalCoverage
if [[ $? -ne 0 ]]; then
exit 1
fi
......@@ -92,7 +93,6 @@ fi
echo_success "===================RUN DT-LLT TESTCASES END========================="
cd $ISULAD_COPY_PATH
sed -i 's/fd == STDIN_FILENO || fd == STDOUT_FILENO || fd == STDERR_FILENO/fd == 0 || fd == 1 || fd == 2 || fd >= 1000/g' ./src/utils/cutils/utils.c
# build rest version
cd $ISULAD_COPY_PATH
......
......@@ -65,8 +65,8 @@ struct lengths {
};
const char * const g_containerstatusstr[] = { "unknown", "inited", "starting", "running",
"exited", "paused", "restarting"
};
"exited", "paused", "restarting"
};
struct filter_field {
char *name;
......
......@@ -528,7 +528,7 @@ out:
return ret;
}
int devmapper_clean_up(const struct graphdriver *driver)
int devmapper_clean_up(struct graphdriver *driver)
{
if (driver == NULL) {
ERROR("Invalid input param to cleanup devicemapper");
......
......@@ -66,7 +66,7 @@ int devmapper_get_layer_metadata(const char *id, const struct graphdriver *drive
int devmapper_get_driver_status(const struct graphdriver *driver, struct graphdriver_status *status);
int devmapper_clean_up(const struct graphdriver *driver);
int devmapper_clean_up(struct graphdriver *driver);
int devmapper_repair_lowers(const char *id, const char *parent, const struct graphdriver *driver);
......
......@@ -368,12 +368,27 @@ void free_graphdriver_mount_opts(struct driver_mount_opts *opts)
int graphdriver_cleanup(void)
{
int ret = 0;
if (g_graphdriver == NULL) {
ERROR("Driver not inited yet");
return -1;
ret = -1;
goto out;
}
if (g_graphdriver->ops->clean_up(g_graphdriver) != 0) {
ret = -1;
goto out;
}
return g_graphdriver->ops->clean_up(g_graphdriver);
free((char *)g_graphdriver->home);
g_graphdriver->home = NULL;
free(g_graphdriver->backing_fs);
g_graphdriver->backing_fs = NULL;
g_graphdriver = NULL;
out:
return ret;
}
int graphdriver_try_repair_lowers(const char *id, const char *parent)
......
......@@ -74,7 +74,7 @@ struct graphdriver_ops {
int (*get_driver_status)(const struct graphdriver *driver, struct graphdriver_status *status);
int (*clean_up)(const struct graphdriver *driver);
int (*clean_up)(struct graphdriver *driver);
int (*try_repair_lowers)(const char *id, const char *parent, const struct graphdriver *driver);
......
......@@ -1775,12 +1775,38 @@ out:
return ret;
}
int overlay2_clean_up(const struct graphdriver *driver)
static void free_overlay_options(struct overlay_options *opts)
{
if (opts == NULL) {
return ;
}
free((char *)opts->mount_options);
opts->mount_options = NULL;
free(opts);
}
int overlay2_clean_up(struct graphdriver *driver)
{
int ret = 0;
if (driver == NULL) {
return -1;
ret = -1;
goto out;
}
if (umount(driver->home) != 0) {
ret = -1;
goto out;
}
return umount(driver->home);
free_pquota_control(driver->quota_ctrl);
driver->quota_ctrl = NULL;
free_overlay_options(driver->overlay_opts);
driver->overlay_opts = NULL;
out:
return ret;
}
static int check_lower_valid(const char *driver_home, const char *lower)
......
......@@ -59,7 +59,7 @@ int overlay2_get_layer_metadata(const char *id, const struct graphdriver *driver
int overlay2_get_driver_status(const struct graphdriver *driver, struct graphdriver_status *status);
int overlay2_clean_up(const struct graphdriver *driver);
int overlay2_clean_up(struct graphdriver *driver);
void free_driver_create_opts(struct driver_create_opts *opts);
......
......@@ -308,7 +308,7 @@ static void get_next_project_id(const char *dirpath, struct pquota_control *ctrl
return;
}
static void free_pquota_control(struct pquota_control *ctrl)
void free_pquota_control(struct pquota_control *ctrl)
{
if (ctrl == NULL) {
return;
......
......@@ -97,6 +97,8 @@ struct pquota_control {
struct pquota_control *project_quota_control_init(const char *home_dir, const char *fs);
void free_pquota_control(struct pquota_control *ctrl);
#ifdef __cplusplus
}
#endif
......
......@@ -536,6 +536,7 @@ static int util_mount_from_handler(const char *src, const char *dst, const char
goto out;
}
out:
free(mntdata);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册