Skip to content

Seems tidy.c has sprung a leak #791

Closed

Description

@geoffmcl

Now and then I build a sanitized version of tidy, for testing...

Using a command like -

cmake ../..  -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_VERBOSE_MAKEFILE=ON
make

turned up a sanitizer error -

make[2]: Entering directory '/home/geoff/projects/html_tidy/tidy-html5/build/sanitize'
Generate /home/geoff/projects/html_tidy/tidy-html5/build/sanitize/tidy-help.xml
./tidy -xml-help > /home/geoff/projects/html_tidy/tidy-html5/build/sanitize/tidy-help.xml

=================================================================
==6114==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 298 byte(s) in 18 object(s) allocated from:
    #0 0x7fcda2cc0b50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
    #1 0x5642905311f3 in stringWithFormat /home/geoff/projects/html_tidy/tidy-html5/console/tidy.c:112
    #2 0x564290531bbf in localize_option_names /home/geoff/projects/html_tidy/tidy-html5/console/tidy.c:408
    #3 0x5642905386cf in xml_help /home/geoff/projects/html_tidy/tidy-html5/console/tidy.c:1875
    #4 0x56429053999d in main /home/geoff/projects/html_tidy/tidy-html5/console/tidy.c:2258
    #5 0x7fcda2812b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: 298 byte(s) leaked in 18 allocation(s).
CMakeFiles/man.dir/build.make:64: recipe for target 'man' failed
make[2]: *** [man] Error 1
make[2]: Leaving directory '/home/geoff/projects/html_tidy/tidy-html5/build/sanitize'
CMakeFiles/Makefile2:181: recipe for target 'CMakeFiles/man.dir/all' failed
make[1]: *** [CMakeFiles/man.dir/all] Error 2
make[1]: Leaving directory '/home/geoff/projects/html_tidy/tidy-html5/build/sanitize'
Makefile:154: recipe for target 'all' failed
make: *** [all] Error 2

Looks like the xml_help generator misses freeing one of the allocations...

That fixed turned up another in printXMLCrossRefEqConsole similar...

Suggests a patch like -

diff --git a/console/tidy.c b/console/tidy.c
index a7880f6..ee4f780 100644
--- a/console/tidy.c
+++ b/console/tidy.c
@@ -1741,6 +1741,10 @@ static void printXMLCrossRefEqConsole(TidyDoc tdoc,   /**< The Tidy document. */
             free((tmbstr)localHit.name3);
             free(localName);
         }
+        if ( localHit.eqconfig )
+        {
+            free((tmbstr)localHit.eqconfig);
+        }
 
     }
     else
@@ -1887,6 +1891,7 @@ static void xml_help( void )
         if (localPos.name1) free((tmbstr)localPos.name1);
         if (localPos.name2) free((tmbstr)localPos.name2);
         if (localPos.name3) free((tmbstr)localPos.name3);
+        if (localPos.eqconfig) free((tmbstr)localPos.eqconfig);
     }
 
     printf( "</cmdline>\n" );

Then I get a clean build...

Much appreciated if someone could apply the patch, test, and report... thanks...

Activity

  1. added a commit that references this issue on Jan 9, 2019
  2. geoffmcl commented on Jan 9, 2019

    @geoffmcl
    ContributorAuthor

    Or you could pull the issue-791 branch, test and report... thanks...

  3. geoffmcl commented on Mar 18, 2019

    @geoffmcl
    ContributorAuthor

    Have now created PR #809 to free an allocation used in -xml-help generation...

  4. added a commit that references this issue on Jun 7, 2019
  5. added a commit that references this issue on Nov 11, 2024
    dcf56a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions