Git Product home page Git Product logo

onecode's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

onecode's Issues

memory leak

Hi, @thegenemyers , I found two memory leak in ONElib.c.

I use the following Makefile to complie your source code.

diff --git a/Makefile b/Makefile
index d8e216a..ad6b9ce 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 
 DEST_DIR = ~/bin
 
-CFLAGS = -O3 -Wall -fPIC -Wextra -Wno-unused-result -fno-strict-aliasing -DNDEBUG # NDEBUG drops asserts
+CFLAGS = -O0 -Wall -fPIC -Wextra -Wno-unused-result -fno-strict-aliasing -DNDEBUG -fsanitize=address -ggdb # NDEBUG drops asserts
 #CFLAGS = -g -Wall -Wextra -fno-strict-aliasing  # for debugging
 
 CCPP = g++

and then I run make test, the LeakSanitizer detect memory leaks

==190479==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 805 byte(s) in 17 object(s) allocated from:
    #0 0x7f098f695d10 in strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:578
    #1 0x55f6aeaaadcc in schemaLoadRecord /home/dwp/source-code-github/ONEcode/ONElib.c:262
    #2 0x55f6aeaabbb4 in oneSchemaCreateFromFile /home/dwp/source-code-github/ONEcode/ONElib.c:341
    #3 0x55f6aeaac4ca in oneSchemaCreateFromText /home/dwp/source-code-github/ONEcode/ONElib.c:408
    #4 0x55f6aeaac6ab in oneSchemaCreateDynamic /home/dwp/source-code-github/ONEcode/ONElib.c:427
    #5 0x55f6aeab534e in oneFileOpenRead /home/dwp/source-code-github/ONEcode/ONElib.c:1382
    #6 0x55f6aeaa7676 in main /home/dwp/source-code-github/ONEcode/ONEview.c:131
    #7 0x7f098f3e8c89 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

Direct leak of 805 byte(s) in 17 object(s) allocated from:
    #0 0x7f098f695d10 in strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:578
    #1 0x55f6aeaaadcc in schemaLoadRecord /home/dwp/source-code-github/ONEcode/ONElib.c:262
    #2 0x55f6aeaabbb4 in oneSchemaCreateFromFile /home/dwp/source-code-github/ONEcode/ONElib.c:341
    #3 0x55f6aeaac4ca in oneSchemaCreateFromText /home/dwp/source-code-github/ONEcode/ONElib.c:408
    #4 0x55f6aeaac6ab in oneSchemaCreateDynamic /home/dwp/source-code-github/ONEcode/ONElib.c:427
    #5 0x55f6aeaba092 in oneFileOpenWriteFrom /home/dwp/source-code-github/ONEcode/ONElib.c:1872
    #6 0x55f6aeaa787a in main /home/dwp/source-code-github/ONEcode/ONEview.c:146
    #7 0x7f098f3e8c89 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

Direct leak of 13 byte(s) in 1 object(s) allocated from:
    #0 0x7f098f69bbc7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x55f6aeacc145 in myalloc /home/dwp/source-code-github/ONEcode/ONElib.c:4129
    #2 0x55f6aeab8f7f in oneFileOpenWriteNew /home/dwp/source-code-github/ONEcode/ONElib.c:1775
    #3 0x55f6aeaba4a7 in oneFileOpenWriteFrom /home/dwp/source-code-github/ONEcode/ONElib.c:1888
    #4 0x55f6aeaa787a in main /home/dwp/source-code-github/ONEcode/ONEview.c:146
    #5 0x7f098f3e8c89 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: 1623 byte(s) leaked in 35 allocation(s).
make: *** [Makefile:47: test] Error 1

there are two memory leak

one place at line-262 in ONElib.c, looks like vs->nDefn not correctly update. So I add one line here, and rerun make test๏ผŒ memory leak was fixed.

diff --git a/ONElib.c b/ONElib.c
index 6574533..2975f8b 100644
--- a/ONElib.c
+++ b/ONElib.c
@@ -254,12 +254,18 @@ static OneSchema *schemaLoadRecord (OneSchema *vs, OneFile *vf)
       break ;
     case 'G': // group another object type
       schemaAddGroup (vs, oneChar(vf,0)) ;
-      if (oneReadComment (vf)) vs->defnComment[vs->nDefn-1] = strdup (oneReadComment(vf)) ;
+      if (oneReadComment (vf)) {
+        vs->defnComment[vs->nDefn] = strdup (oneReadComment(vf));
+        vs->nDefn++;
+      }
       break ;
     case 'O': // object type
     case 'D': // standard record type
       schemaAddInfoFromLine (vs, vf, oneChar(vf,0), vf->lineType) ;
-      if (oneReadComment (vf)) vs->defnComment[vs->nDefn-1] = strdup (oneReadComment(vf)) ;
+      if (oneReadComment(vf)) {
+        vs->defnComment[vs->nDefn] = strdup(oneReadComment(vf));
+        vs->nDefn++;
+      };
       break ;
     default:
       die ("unrecognized schema line %d starting with %c", vf->line, vf->lineType) ;

another place at line-1775 in ONElib.c. Forget free tempPath after alloc memory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.