Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valgrind warnings, memory leaks #35

Open
Gudwlin opened this issue Dec 28, 2024 · 0 comments
Open

Valgrind warnings, memory leaks #35

Gudwlin opened this issue Dec 28, 2024 · 0 comments

Comments

@Gudwlin
Copy link

Gudwlin commented Dec 28, 2024

Describe the bug
Invalid memory access in various functions.

What data setup do we need to do?
BemiDB(main) with PostgreSQL (REL_17_STABLE).
Valgrind-3.23.0.

To reproduce valgrind warnings follow these steps:

  1. Install Valgrind-3.23.0.
sudo apt-install valgrind
  1. Apply the patch to pg_regress.c. This patch allows make installcheck-world tests to run and be redirected for use with BemiDB. (attached to this tread). Gist with patch.
git apply pg_regressc.patch
  1. Run BemiDB under Valgrind.
valgrind --quiet --exit-on-first-error=no --error-exitcode=1 --leak-check=no --time-stamp=yes --gen-suppressions=all --trace-children=yes --suppressions=/home/gudwlin/postgres/src/tools/valgrind.supp ./bemidb -log-level DEBUG start > bemidbvg.log 2>&1
  1. Running tests
make installcheck-world EXTRA_REGRESS_OPTS="--host=localhost --port=54321 --dbname=bemidb"
  1. Observe the Valgrind output.

Examples of incorrect memory access

  1. Invalid write of size 32
==00:00:48:32.017 406916== Thread 3:
==00:00:48:32.017 406916== Invalid read of size 32
==00:00:48:32.022 406916==    at 0x6C6640: indexbytebody (indexbyte_amd64.s:131)
==00:00:48:32.022 406916==  Address 0x4f1a6830 is 0 bytes inside a block of size 21 alloc'd
==00:00:48:32.026 406916==    at 0x4848858: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==00:00:48:32.028 406916==    by 0x4CC0D7E: strdup (strdup.c:42)
==00:00:48:32.030 406916==    by 0x1040231: pg_query_deparse_protobuf (pg_query_deparse.c:28)
==00:00:48:32.031 406916==    by 0x102959F: _cgo_04d7a251dcb7_Cfunc_pg_query_deparse_protobuf_direct_args (cgo-gcc-prolog:68)
==00:00:48:32.032 406916==    by 0x737B03: runtime.asmcgocall.abi0 (asm_amd64.s:923)
==00:00:48:32.032 406916==    by 0xC0004868BF: ???
==00:00:48:32.032 406916== 
{
   <insert_a_suppression_name_here>
   Memcheck:Addr32
   fun:indexbytebody
}
  1. Invalid write of size 8
==00:00:53:17.792 406916== Invalid read of size 8
==00:00:53:17.792 406916==    at 0x7B32E9: fmt.(*pp).doPrintln (print.go:1216)
==00:00:53:17.792 406916==  Address 0xc0007a47e0 is in a rw- anonymous segment
==00:00:53:17.792 406916== 
{
   <insert_a_suppression_name_here>
   Memcheck:Addr8
   fun:fmt.(*pp).doPrintln
}
==00:00:53:17.776 406916== Invalid read of size 8
==00:00:53:17.777 406916==    at 0x760A74: reflect.packEface (value.go:140)
==00:00:53:17.777 406916==  Address 0xc0007a2000 is in a rw- anonymous segment
==00:00:53:17.777 406916== 
{
   <insert_a_suppression_name_here>
   Memcheck:Addr8
   fun:reflect.packEface
}
==00:00:53:17.737 406916== Invalid read of size 8
==00:00:53:17.737 406916==    at 0x73CDAE: internal/reflectlite.Swapper.func9 (swapper.go:68)
==00:00:53:17.737 406916==  Address 0xc0007a40d0 is in a rw- anonymous segment
==00:00:53:17.737 406916== 
{
   <insert_a_suppression_name_here>
   Memcheck:Addr8
   fun:internal/reflectlite.Swapper.func9
}
==00:00:53:17.690 406916== Invalid read of size 8
==00:00:53:17.691 406916==    at 0x1007C32: main.(*QueryHandler).remapQuery (query_handler.go:378)
==00:00:53:17.691 406916==  Address 0xc0007a2058 is in a rw- anonymous segment
==00:00:53:17.691 406916== 
{
   <insert_a_suppression_name_here>
   Memcheck:Addr8
   fun:main.(*QueryHandler).remapQuery
}
  1. Conditional jump or move depends on uninitialized values
==00:00:00:02.647 406401== Conditional jump or move depends on uninitialised value(s)
==00:00:00:02.647 406401==    at 0x713943: runtime.adjustctxt (stack.go:585)
==00:00:00:02.647 406401==    by 0x713D31: runtime.copystack (stack.go:929)
==00:00:00:02.647 406401==    by 0x714408: runtime.newstack (stack.go:1126)
...
{
   <insert_a_suppression_name_here>
   Memcheck:Cond
   fun:runtime.adjustctxt
   fun:runtime.copystack
   fun:runtime.newstack
   obj:*
}

Expected behavior
Under Valgrind, the application should run without critical warnings.

Best regards,
Artyom Zarubin
Postgres Professional: https://postgrespro.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant