par icon indicating copy to clipboard operation
par copied to clipboard

Use of uninitialized memory and memory leaks

Open turol opened this issue 2 years ago • 0 comments

Valgrind says:

Conditional jump or move depends on uninitialised value(s)
   at 0x48A74F8: sqrt (w_sqrt_compat.c:31)
   by 0x109F93: par_shapes__normalize3 (par_shapes.h:291)
   by 0x10CC99: par_shapes_scale (par_shapes.h:840)
   by 0x110364: par_shapes_weld (par_shapes.h:1805)
   by 0x10A1C6: par_shapes__compute_welded_normals (par_shapes.h:324)
   by 0x10A9F6: par_shapes_create_parametric (par_shapes.h:492)
   by 0x10A2D6: par_shapes_create_cylinder (par_shapes.h:343)
   by 0x111360: main (test_shapes.c:17)
 Uninitialised value was created by a heap allocation
   at 0x483F7B5: malloc (vg_replace_malloc.c:381)
   by 0x10A189: par_shapes__compute_welded_normals (par_shapes.h:322)
   by 0x10A9F6: par_shapes_create_parametric (par_shapes.h:492)
   by 0x10A2D6: par_shapes_create_cylinder (par_shapes.h:343)
   by 0x111360: main (test_shapes.c:17)

and also memory leaks:

2,772 bytes in 1 blocks are definitely lost in loss record 1 of 2
   at 0x483F7B5: malloc (vg_replace_malloc.c:381)
   by 0x10A189: par_shapes__compute_welded_normals (par_shapes.h:322)
   by 0x10A9F6: par_shapes_create_parametric (par_shapes.h:492)
   by 0x10A524: par_shapes_create_klein_bottle (par_shapes.h:404)
   by 0x111B28: main (test_shapes.c:77)

This is caused by m->normals already being set and unconditionally overwritten here:

https://github.com/prideout/par/blob/10e008d13ccb7e67b34f783674f220917f672a7b/par_shapes.h#L322

I'm not sure what the right fix is here.

turol avatar Aug 05 '22 10:08 turol