]> git.proxmox.com Git - libgit2.git/blob - tests/buf/oom.c
Fix crash in free() when git_buf_grow() fails.
[libgit2.git] / tests / buf / oom.c
1 #include "clar_libgit2.h"
2 #include "buffer.h"
3
4 #if defined(GIT_ARCH_64)
5 #define TOOBIG 0xffffffffffffff00
6 #else
7 #define TOOBIG 0xffffff00
8 #endif
9
10 /**
11 * If we make a ridiculously large request the first time we
12 * actually allocate some space in the git_buf, the realloc()
13 * will fail. And because the git_buf_grow() wrapper always
14 * sets mark_oom, the code in git_buf_try_grow() will free
15 * the internal buffer and set it to git_buf__oom.
16 *
17 * We initialized the internal buffer to (the static variable)
18 * git_buf__initbuf. The purpose of this test is to make sure
19 * that we don't try to free the static buffer.
20 */
21 void test_buf_oom__grow(void)
22 {
23 git_buf buf = GIT_BUF_INIT;
24
25 git_buf_clear(&buf);
26
27 cl_assert(git_buf_grow(&buf, TOOBIG) == -1);
28 cl_assert(git_buf_oom(&buf));
29
30 git_buf_free(&buf);
31 }