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 report use of uninitialized memory #70

Open
mingodad opened this issue Mar 28, 2022 · 2 comments
Open

Valgrind report use of uninitialized memory #70

mingodad opened this issue Mar 28, 2022 · 2 comments

Comments

@mingodad
Copy link

Build camlrum with -g -O0 and building and and running examples/mls on ubuntu 18.04 64 bits we get this output from valgrind:

valgrind --leak-check=full ./a.out 
==25841== Memcheck, a memory error detector
==25841== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==25841== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==25841== Command: ./a.out
==25841== 
==25841== Conditional jump or move depends on uninitialised value(s)
==25841==    at 0x11C414: darken (major_gc.c:496)
==25841==    by 0x11DC1F: modify (memory.c:200)
==25841==    by 0x123137: mkexnname (sys.c:206)
==25841==    by 0x1232F3: sys_init (sys.c:241)
==25841==    by 0x118AF5: main (main.c:251)
==25841== 
==25841== Conditional jump or move depends on uninitialised value(s)
==25841==    at 0x11C42B: darken (major_gc.c:496)
==25841==    by 0x11DC1F: modify (memory.c:200)
==25841==    by 0x123137: mkexnname (sys.c:206)
==25841==    by 0x1232F3: sys_init (sys.c:241)
==25841==    by 0x118AF5: main (main.c:251)
==25841== 
==25841== Conditional jump or move depends on uninitialised value(s)
==25841==    at 0x11DC64: modify (memory.c:200)
==25841==    by 0x123137: mkexnname (sys.c:206)
==25841==    by 0x1232F3: sys_init (sys.c:241)
==25841==    by 0x118AF5: main (main.c:251)
==25841== 
==25841== Conditional jump or move depends on uninitialised value(s)
==25841==    at 0x11DC77: modify (memory.c:200)
==25841==    by 0x123137: mkexnname (sys.c:206)
==25841==    by 0x1232F3: sys_init (sys.c:241)
==25841==    by 0x118AF5: main (main.c:251)
==25841== 
Makefile      a.out         mls.sml       mls.ui        mls.uo        
Makefile.w32  
==25841== 
==25841== HEAP SUMMARY:
==25841==     in use at exit: 656,664 bytes in 15 blocks
==25841==   total heap usage: 22 allocs, 7 frees, 718,160 bytes allocated
==25841== 
==25841== 30,712 bytes in 1 blocks are possibly lost in loss record 9 of 13
==25841==    at 0x4C32F6D: malloc (vg_replace_malloc.c:380)
==25841==    by 0x1177CF: expandcode (expand.c:363)
==25841==    by 0x111518: interprete (interp.c:181)
==25841==    by 0x118B36: main (main.c:253)
==25841== 
==25841== 266,256 bytes in 1 blocks are possibly lost in loss record 13 of 13
==25841==    at 0x4C32F6D: malloc (vg_replace_malloc.c:380)
==25841==    by 0x1180C2: aligned_malloc (misc.c:143)
==25841==    by 0x11CDCF: init_major_heap (major_gc.c:725)
==25841==    by 0x1247BD: init_gc (gc_ctrl.c:197)
==25841==    by 0x1189BB: main (main.c:224)
==25841== 
==25841== LEAK SUMMARY:
==25841==    definitely lost: 0 bytes in 0 blocks
==25841==    indirectly lost: 0 bytes in 0 blocks
==25841==      possibly lost: 296,968 bytes in 2 blocks
==25841==    still reachable: 359,696 bytes in 13 blocks
==25841==         suppressed: 0 bytes in 0 blocks
==25841== Reachable blocks (those to which a pointer was found) are not shown.
==25841== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==25841== 
==25841== Use --track-origins=yes to see where uninitialised values come from
==25841== For lists of detected and suppressed errors, rerun with: -s
==25841== ERROR SUMMARY: 74 errors from 6 contexts (suppressed: 0 from 0)
@mingodad
Copy link
Author

Looking at Camel Light (cl75) I can see that the code that valgrind report is an extension by mosml, the camlrun from cl75 doesn't show any error in valgrind other than memory leaks.

@mingodad
Copy link
Author

Using Initialize instead of Modify then valgrind doesn't report invalid memory usage anymore and no signs of undesired side effects so far (building all mosml under valgrind).

------------------------------ src/runtime/sys.c ------------------------------

index 98b3be3..f214d46 100644
@@ -203,7 +203,7 @@ value mkexnname(char* name) {
   Push_roots(r, 1);
   r[0] = copy_string(name);
   ref = alloc_shr(1, Reference_tag);
-  modify(&Field(ref, 0), r[0]);
+  initialize(&Field(ref, 0), r[0]);
   Pop_roots();
   return ref;
 }

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