diff options
author | Russell Belfer <rb@github.com> | 2012-08-01 14:49:47 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-08-22 16:07:19 -0700 |
commit | b769e936d0118b7c3870ffc082b44254164bfedd (patch) | |
tree | 7719f21324b4881537952a6779b37bdae195616a | |
parent | 0e26202cd587f45edc96966ed327e93354e2102e (diff) | |
download | libgit2-b769e936d0118b7c3870ffc082b44254164bfedd.tar.gz |
Don't reference stack vars in cleanup callback
If you use the clar cleanup callback function, you can't pass a
reference pointer to a stack allocated variable because when the
cleanup function runs, the stack won't exist anymore.
-rw-r--r-- | tests-clar/core/mkdir.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/tests-clar/core/mkdir.c b/tests-clar/core/mkdir.c index 167639b07..d7723be8d 100644 --- a/tests-clar/core/mkdir.c +++ b/tests-clar/core/mkdir.c @@ -102,8 +102,11 @@ void test_core_mkdir__with_base(void) static void cleanup_chmod_root(void *ref) { mode_t *mode = ref; - if (*mode != 0) + + if (*mode != 0) { (void)p_umask(*mode); + git__free(mode); + } git_futils_rmdir_r("r", GIT_DIRREMOVAL_EMPTY_HIERARCHY); } @@ -111,12 +114,12 @@ static void cleanup_chmod_root(void *ref) void test_core_mkdir__chmods(void) { struct stat st; - mode_t old = 0; + mode_t *old = git__malloc(sizeof(mode_t)); + *old = p_umask(022); - cl_set_cleanup(cleanup_chmod_root, &old); + cl_set_cleanup(cleanup_chmod_root, old); cl_git_pass(git_futils_mkdir("r", NULL, 0777, 0)); - old = p_umask(022); cl_git_pass(git_futils_mkdir("mode/is/important", "r", 0777, GIT_MKDIR_PATH)); |