Skip to content

Commit

Permalink
fix(scap): Potential leak of memory pointed to by 'heap_tinfo'
Browse files Browse the repository at this point in the history
```
/code/falcosecurity/libs/userspace/libscap/scap_procs.c:144:11: warning: Potential leak of memory pointed to by 'heap_tinfo' [clang-analyzer-unix.Malloc]
                        return scap_errprintf(error, errno, "can't allocate procinfo struct");
                               ^
/code/falcosecurity/libs/userspace/libscap/strerror.h:30:24: note: expanded from macro 'scap_errprintf'
                       ^
/code/falcosecurity/libs/userspace/libscap/scap_procs.c:82:5: note: Assuming 'fdinfo' is equal to NULL
        if(fdinfo != NULL)
           ^~~~~~~~~~~~~~
/code/falcosecurity/libs/userspace/libscap/scap_procs.c:82:2: note: Taking false branch
        if(fdinfo != NULL)
        ^
/code/falcosecurity/libs/userspace/libscap/scap_procs.c:141:33: note: Memory is allocated
                scap_threadinfo *heap_tinfo = malloc(sizeof(*heap_tinfo));
                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/code/falcosecurity/libs/userspace/libscap/scap_procs.c:142:6: note: Assuming 'tinfo' is equal to NULL
                if(tinfo == NULL)
                   ^~~~~~~~~~~~~
/code/falcosecurity/libs/userspace/libscap/scap_procs.c:142:3: note: Taking true branch
                if(tinfo == NULL)
                ^
/code/falcosecurity/libs/userspace/libscap/scap_procs.c:144:11: note: Potential leak of memory pointed to by 'heap_tinfo'
                        return scap_errprintf(error, errno, "can't allocate procinfo struct");
                               ^
```

Signed-off-by: Angelo Puglisi <angelopuglisi86@gmail.com>
  • Loading branch information
deepskyblue86 authored and poiana committed Dec 18, 2023
1 parent 6134091 commit 4706f4c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion userspace/libscap/scap_procs.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int32_t default_proc_entry_callback(void* context, char* error, int64_t tid, sca
// add a thread
// get a copy of tinfo on the heap
scap_threadinfo *heap_tinfo = malloc(sizeof(*heap_tinfo));
if(tinfo == NULL)
if(heap_tinfo == NULL)
{
return scap_errprintf(error, errno, "can't allocate procinfo struct");
}
Expand Down

0 comments on commit 4706f4c

Please sign in to comment.