forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemoryleak.c
47 lines (34 loc) · 801 Bytes
/
memoryleak.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* @file
*
* @brief Benchmark for KDB
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*/
#include <stdio.h>
#include <benchmarks.h>
#include <kdb.h>
#include <unistd.h>
#define NUM_RUNS 30
int main (void)
{
KDB * handles[NUM_RUNS];
KeySet * keysets[NUM_RUNS];
Key * parentKey = keyNew ("user:/", KEY_END);
for (size_t i = 0; i < NUM_RUNS; ++i)
{
KDB * handle = kdbOpen (NULL, parentKey);
KeySet * ks = ksNew (0, KS_END);
kdbGet (handle, ks, parentKey);
printf ("Retrieved %d keys\n", (int) ksGetSize (ks));
handles[i] = handle;
keysets[i] = ks;
}
for (size_t i = 0; i < NUM_RUNS; ++i)
{
printf ("Freeing %d keys\n", (int) ksGetSize (keysets[i]));
kdbClose (handles[i], parentKey);
ksDel (keysets[i]);
}
keyDel (parentKey);
}