Simple PB GUI program triggering VALGRIND to get crazy?

Linux specific forum
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Simple PB GUI program triggering VALGRIND to get crazy?

Post by Kukulkan »

Hi,

I just wondered what valgrind (http://valgrind.org/) will do if I let it check a simple PB GUI program. But is this ok???

PB 5.42 LTS on Kubuntu 14.04 (amd64):

Code: Select all

CompilerIf #PB_Compiler_Unicode
  #XmlEncoding = #PB_UTF8
CompilerElse 
  #XmlEncoding = #PB_Ascii
CompilerEndIf

Procedure main()
  Protected XML.s, Event.i, evType.i, evGadget.i
  
  XML  = "<window id='#PB_Any' name='mainWin' text='Test' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
         "  <vbox expand='item:1'>" +
         "    <hbox expand='item:1'>" +
         "      <canvas name='draw' width='300' height='120'/>" +
         "      <vbox expand='item:2'>" +
         "        <button name='clear' text='clear' />" +
         "        <empty />" +
         "      </vbox>" +
         "    </hbox>" +
         "    <gridbox columns='2' colexpand='item:2'>" +
         "      <text text='Device:' name='lblDevice' flags='#PB_Text_Right'/>" +
         "      <combobox name='device' />" +       
         "    </gridbox>" +
         "  </vbox>" +
         "</window>"
  
  Protected xm.i = CatchXML(#PB_Any, @XML, StringByteLength(XML), 0, #XmlEncoding)
  Protected dialog.i = CreateDialog(#PB_Any)
  If OpenXMLDialog(dialog.i, xm.i, "mainWin") = 0
    Debug "Dialog error: " + DialogError(dialog.i): ProcedureReturn 0
  EndIf
  
  Repeat
    Event = WaitWindowEvent(10)
    If Event = #PB_Event_Gadget
      evType.i = EventType()
      evGadget.i = EventGadget()
    EndIf
  Until Event = #PB_Event_CloseWindow
EndProcedure

main()
Compiled and run with "valgrind ./test" results:

Code: Select all

Thousands of
==26360== Conditional jump or move depends on uninitialised value(s)
==26360==    at 0x56BE651: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56BEB54: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x568FF4D: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56900F2: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x5688127: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x5691147: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56C2DC1: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x566BA63: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56DCA3C: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56B0411: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56B4DF4: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56B5A5E: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)

...

Hundreds of
==26360== Conditional jump or move depends on uninitialised value(s)
==26360==    at 0x56BF3EF: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56C2DD8: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x566BA63: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56DCA3C: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56B0411: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56B4DF4: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56B5A5E: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56B0411: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x56731E1: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x566D168: ??? (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0x5666994: cairo_stroke (in /usr/lib/x86_64-linux-gnu/libcairo.so.2.11301.0)
==26360==    by 0xEDEAC9E: Oxygen::Style::renderArrow(_cairo*, GtkArrowType, int, int, int, int, Oxygen::QtSettings::ArrowSize, Oxygen::StyleOptions const&, Oxygen::AnimationData const&, Oxygen::Palette::Role) const (in /usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/theming-engines/liboxygen-gtk.so)

...

==26360== More than 1000 different errors detected.  I'm not reporting any more.
==26360== Final error counts will be inaccurate.  Go fix your program!
==26360== Rerun with --error-limit=no to disable this cutoff.  Note
==26360== that errors may occur in your program without prior warning from
==26360== Valgrind, because errors are no longer being displayed.
==26360== 
==26360== 
==26360== HEAP SUMMARY:
==26360==     in use at exit: 1,682,682 bytes in 22,555 blocks
==26360==   total heap usage: 96,631 allocs, 74,076 frees, 20,106,033 bytes allocated
==26360== 
==26360== LEAK SUMMARY:
==26360==    definitely lost: 8,600 bytes in 24 blocks
==26360==    indirectly lost: 40,080 bytes in 835 blocks
==26360==      possibly lost: 102,561 bytes in 1,722 blocks
==26360==    still reachable: 1,430,777 bytes in 19,275 blocks
==26360==         suppressed: 0 bytes in 0 blocks
If I suppress these errors using
"valgrind --undef-value-errors=no ./test"
I still get this:

Code: Select all

==26898== Memcheck, a memory error detector
==26898== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==26898== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==26898== Command: ./test
==26898== 
==26898== Invalid read of size 8
==26898==    at 0x414CBA: ??? (in /home/volker/test)
==26898==    by 0x44B517: ??? (in /home/volker/test)
==26898==    by 0x414D32: ??? (in /home/volker/test)
==26898==    by 0x41409C: ??? (in /home/volker/test)
==26898==    by 0x10765D17: ???
==26898==    by 0xD1ABF87: ???
==26898==    by 0xD22EAB7: ???
==26898==  Address 0xd22eba0 is 144 bytes inside a block of size 168 free'd
==26898==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26898==    by 0x4E9211: ??? (in /home/volker/test)
==26898==    by 0x419147: ??? (in /home/volker/test)
==26898==    by 0x4188F9: ??? (in /home/volker/test)
==26898==    by 0x414CB6: ??? (in /home/volker/test)
==26898==    by 0x44B517: ??? (in /home/volker/test)
==26898==    by 0x414D32: ??? (in /home/volker/test)
==26898==    by 0x41409C: ??? (in /home/volker/test)
==26898==    by 0x10765D17: ???
==26898==    by 0xD1ABF87: ???
==26898==    by 0xD22EAB7: ???
==26898== 
==26898== Invalid read of size 8
==26898==    at 0x414CCE: ??? (in /home/volker/test)
==26898==    by 0x44B517: ??? (in /home/volker/test)
==26898==    by 0x414D32: ??? (in /home/volker/test)
==26898==    by 0x41409C: ??? (in /home/volker/test)
==26898==    by 0x10765D17: ???
==26898==    by 0xD1ABF87: ???
==26898==    by 0xD22EAB7: ???
==26898==  Address 0xd22eba0 is 144 bytes inside a block of size 168 free'd
==26898==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26898==    by 0x4E9211: ??? (in /home/volker/test)
==26898==    by 0x419147: ??? (in /home/volker/test)
==26898==    by 0x4188F9: ??? (in /home/volker/test)
==26898==    by 0x414CB6: ??? (in /home/volker/test)
==26898==    by 0x44B517: ??? (in /home/volker/test)
==26898==    by 0x414D32: ??? (in /home/volker/test)
==26898==    by 0x41409C: ??? (in /home/volker/test)
==26898==    by 0x10765D17: ???
==26898==    by 0xD1ABF87: ???
==26898==    by 0xD22EAB7: ???
==26898== 
==26898== 
==26898== HEAP SUMMARY:
==26898==     in use at exit: 2,141,586 bytes in 22,855 blocks
==26898==   total heap usage: 131,074 allocs, 108,219 frees, 37,926,618 bytes allocated
==26898== 
==26898== LEAK SUMMARY:
==26898==    definitely lost: 8,600 bytes in 24 blocks
==26898==    indirectly lost: 40,080 bytes in 835 blocks
==26898==      possibly lost: 103,065 bytes in 1,728 blocks
==26898==    still reachable: 1,889,177 bytes in 19,569 blocks
==26898==         suppressed: 0 bytes in 0 blocks
==26898== Rerun with --leak-check=full to see details of leaked memory
==26898== 
==26898== For counts of detected and suppressed errors, rerun with: -v
==26898== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
So there are still memory leaks in this software. Is this okay or is this a bug in PB? Or in my code?
Last edited by Kukulkan on Thu Jul 28, 2016 1:21 pm, edited 1 time in total.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Simple PB GUI program triggering VALGRIND to get crazy?

Post by Keya »

as a 'baseline' how does it compare to a PB program who's source code is nothing more than a "! nop" ?
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Simple PB GUI program triggering VALGRIND to get crazy?

Post by Kukulkan »

Hi keya,

Code: Select all

!nop
this will return:

Code: Select all

==28190== Memcheck, a memory error detector
==28190== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==28190== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==28190== Command: ./test
==28190== 
==28190== 
==28190== HEAP SUMMARY:
==28190==     in use at exit: 0 bytes in 0 blocks
==28190==   total heap usage: 28 allocs, 28 frees, 3,637 bytes allocated
==28190== 
==28190== All heap blocks were freed -- no leaks are possible
==28190== 
==28190== For counts of detected and suppressed errors, rerun with: -v
==28190== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
But trying this:

Code: Select all

CompilerIf #PB_Compiler_Unicode
  #XmlEncoding = #PB_UTF8
CompilerElse 
  #XmlEncoding = #PB_Ascii
CompilerEndIf

Procedure main()
  Protected XML.s, Event.i, evType.i, evGadget.i
  
  XML  = "<window id='#PB_Any' name='mainWin' text='Test' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>" +
         "</window>"
  
  Protected xm.i = CatchXML(#PB_Any, @XML, StringByteLength(XML), 0, #XmlEncoding)
  Protected dialog.i = CreateDialog(#PB_Any)
  If OpenXMLDialog(dialog.i, xm.i, "mainWin") = 0
    Debug "Dialog error: " + DialogError(dialog.i): ProcedureReturn 0
  EndIf
  
  Repeat
    Event = WaitWindowEvent(10)
  Until Event = #PB_Event_CloseWindow
EndProcedure

main()
Results in

Code: Select all

==28459== Memcheck, a memory error detector
==28459== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==28459== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==28459== Command: ./test
==28459== 
==28459== Invalid read of size 8
==28459==    at 0x414C9A: ??? (in /home/volker/test)
==28459==    by 0x44B4F7: ??? (in /home/volker/test)
==28459==    by 0x414D12: ??? (in /home/volker/test)
==28459==    by 0x41409C: ??? (in /home/volker/test)
==28459==  Address 0xd22d800 is 144 bytes inside a block of size 168 free'd
==28459==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28459==    by 0x4E91F1: ??? (in /home/volker/test)
==28459==    by 0x419127: ??? (in /home/volker/test)
==28459==    by 0x4188D9: ??? (in /home/volker/test)
==28459==    by 0x414C96: ??? (in /home/volker/test)
==28459==    by 0x44B4F7: ??? (in /home/volker/test)
==28459==    by 0x414D12: ??? (in /home/volker/test)
==28459==    by 0x41409C: ??? (in /home/volker/test)
==28459== 
==28459== Invalid read of size 8
==28459==    at 0x414CAE: ??? (in /home/volker/test)
==28459==    by 0x44B4F7: ??? (in /home/volker/test)
==28459==    by 0x414D12: ??? (in /home/volker/test)
==28459==    by 0x41409C: ??? (in /home/volker/test)
==28459==  Address 0xd22d800 is 144 bytes inside a block of size 168 free'd
==28459==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28459==    by 0x4E91F1: ??? (in /home/volker/test)
==28459==    by 0x419127: ??? (in /home/volker/test)
==28459==    by 0x4188D9: ??? (in /home/volker/test)
==28459==    by 0x414C96: ??? (in /home/volker/test)
==28459==    by 0x44B4F7: ??? (in /home/volker/test)
==28459==    by 0x414D12: ??? (in /home/volker/test)
==28459==    by 0x41409C: ??? (in /home/volker/test)
==28459== 
==28459== 
==28459== HEAP SUMMARY:
==28459==     in use at exit: 1,109,277 bytes in 14,912 blocks
==28459==   total heap usage: 70,240 allocs, 55,328 frees, 15,433,627 bytes allocated
==28459== 
==28459== LEAK SUMMARY:
==28459==    definitely lost: 376 bytes in 2 blocks
==28459==    indirectly lost: 240 bytes in 1 blocks
==28459==      possibly lost: 92,085 bytes in 1,578 blocks
==28459==    still reachable: 955,968 bytes in 12,907 blocks
==28459==         suppressed: 0 bytes in 0 blocks
==28459== Rerun with --leak-check=full to see details of leaked memory
==28459== 
==28459== For counts of detected and suppressed errors, rerun with: -v
==28459== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Looks like the more GUI elements, the more errors. I wanted to find a bug in my lib implementation, but it is impossible to see something if there are so many problems in the PB code itself... :-(
User avatar
Kukulkan
Addict
Addict
Posts: 1352
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Simple PB GUI program triggering VALGRIND to get crazy?

Post by Kukulkan »

I just found that the canvas gadget and the combobox gadget seem to be the source of the most problems. If I remove them from the code in the first post here, it gets much better (but still many problems). But it looks like if every gadget is having problems more or less.

Not sure if the problems are in the PB implementation or if this are problems in libgtk, libcairo, libgobject, libpangocairo or others?
Post Reply