Skip to content

Commit

Permalink
tidy: Ignore false positive memory leak warning.
Browse files Browse the repository at this point in the history
Clang-tidy complains that the sub_read_file function leaks memory at
the return statement at the end of the function, saying that the
memory of the 'sub' variable is leaked.  The pointer is always set as
a result of a function call to parse something, and it typically set
to point to the memory provided by the second argument.  The only
other possible values are nullptr or an error code.  Since this
pointer never owns any memory, there can't be a memory leak.

https://clang.llvm.org/extra/clang-tidy/checks/clang-analyzer-unix.Malloc.html
  • Loading branch information
linuxdude42 committed Dec 6, 2019
1 parent 65b8be3 commit f4490f1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mythtv/libs/libmythtv/xine_demux_sputext.cpp
Expand Up @@ -1120,6 +1120,8 @@ subtitle_t *sub_read_file (demux_sputext_t *demuxstr) {
int n_max;
int timeout;
subtitle_t *first;
// These functions all return either 1) nullptr, 2) (subtitle_t*)ERR,
// or 3) a pointer to the dest parameter.
subtitle_t * (*func[])(demux_sputext_t *demuxstr,subtitle_t *dest)=
{
sub_read_line_microdvd,
Expand Down Expand Up @@ -1164,8 +1166,6 @@ subtitle_t *sub_read_file (demux_sputext_t *demuxstr) {
else timeout *= 10;

while(true) {
subtitle_t *sub;

if(demuxstr->num>=n_max){
n_max+=16;
auto *new_first=(subtitle_t *)realloc(first,n_max*sizeof(subtitle_t));
Expand All @@ -1176,8 +1176,7 @@ subtitle_t *sub_read_file (demux_sputext_t *demuxstr) {
first = new_first;
}

sub = func[demuxstr->format] (demuxstr, &first[demuxstr->num]);

subtitle_t *sub = func[demuxstr->format] (demuxstr, &first[demuxstr->num]);
if (!sub) {
break; /* EOF */
}
Expand Down Expand Up @@ -1223,5 +1222,7 @@ subtitle_t *sub_read_file (demux_sputext_t *demuxstr) {
}
#endif

// No memory leak of 'sub' here. 'Sub' always points to an element in 'first'.
// NOLINT(clang-analyzer-unix.Malloc)
return first;
}

0 comments on commit f4490f1

Please sign in to comment.