Possible memory leak in shell.c

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible memory leak in shell.c

Patricia Monteiro
I've been testing the latest version of SQLite with 3 static analysis tools
(Infer, Clang Static Analyzer and Cppcheck) and they all reported a memory
leak error in shell.c .

The Infer error report is as follows:

shell.c:585: error: MEMORY_LEAK

memory dynamically allocated by call to `realloc()` at line 585, column 15
is not reachable after line 585, column 7.

  583.       if( n+100>nLine ){

  584.         nLine = nLine*2 + 100;

  585. >       zLine = realloc(zLine, nLine);

  586.         if( zLine==0 ) return 0;

  587.       }

This error occurs because if the realloc function fails the memory
previously pointed out by zLine becomes inaccessible, you need to ensure
that realloc! = NULL before doing zLine = realloc (zLine, nLine).
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Possible memory leak in shell.c

Richard Hipp-3
On 7/29/18, Patricia Monteiro <[hidden email]> wrote:
> I've been testing the latest version of SQLite with 3 static analysis tools
> (Infer, Clang Static Analyzer and Cppcheck) and they all reported a memory
> leak error in shell.c .

The shell code has now been modified so that it calls exit(1) if
realloc() ever returns NULL.  I think it was probably already doing
this, eventually, but perhaps not quickly enough for your static
analysis tools to figure that out.  So I've adjusted the code so that
it dies quickly and unambiguously now. Hopefully this will be enough
of a hint to your static analysis tools to get them to stop
complaining.
--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users