added examples

This commit is contained in:
Юрий 2024-05-05 11:32:07 +04:00
parent 5b8692cee7
commit 51e80b0e03
3 changed files with 40 additions and 0 deletions

23
README.md Normal file
View file

@ -0,0 +1,23 @@
# Docker container for valgrind
## Использование
Запуск контейнера:
`docker run -it --rm -v $PWD/path/to/my/files:/valgrind shahfil/valgrind:latest`
Запуск проверки в обычном режиме:
`valgrind ./your_executable`
### Пример использования
```
docker run -it --rm -v $PWD/examples:/valgrind shahfil/valgrind:latest
make
valgrind ./leak
valgrind --leak-check=full -s ./leak
exit
```
или то же самое одной командой:
```
docker run -it --rm -v $PWD/examples:/valgrind shahfil/valgrind:latest /bin/bash -c "make && valgrind ./leak"
```

BIN
examples/leak Executable file

Binary file not shown.

17
examples/leak.cpp Normal file
View file

@ -0,0 +1,17 @@
#include <cstdlib>
#include <iostream>
int
main (void)
{
size_t *n = 0;
n = (size_t *) malloc (sizeof (size_t) * 3);
for (size_t idx = 0; idx < 3; idx++)
{
*(n + idx) = idx;
std::cout << *(n + idx) << std::endl;
}
// free ((void *) n);
return 0;
}