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

Seems tidy.c has sprung a leak #791

Closed
geoffmcl opened this issue Jan 9, 2019 · 2 comments
Closed

Seems tidy.c has sprung a leak #791

geoffmcl opened this issue Jan 9, 2019 · 2 comments
Labels

Comments

@geoffmcl
Copy link
Contributor

geoffmcl commented Jan 9, 2019

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...

geoffmcl added a commit that referenced this issue Jan 9, 2019
@geoffmcl
Copy link
Contributor Author

geoffmcl commented Jan 9, 2019

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

@geoffmcl
Copy link
Contributor Author

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

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

No branches or pull requests

1 participant