Skip to content

Commit 80f41e1

Browse files
Fix double-free in NewModuleFromBufferArgs (#327)
In 0238ec3 the freeing of C strings was changed to use defers. This can cause a double-free, which in the best case it will produce a crash. The reason why this happens is that the memory address at `defer` time is captured for later execution. If `KConfigFilePath` is less than 3, it was being freed and set to NULL. Once the defer executes on function return, the same address we already freed will be passed again. We observed this while upgrading libbpfgo in Parca Agent (parca-dev/parca-agent#1599). Signed-off-by: Francisco Javier Honduvilla Coto <javierhonduco@gmail.com>
1 parent 0238ec3 commit 80f41e1

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

libbpfgo.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ func NewModuleFromBufferArgs(args NewModuleArgs) (*Module, error) {
391391
cBPFBuffSize := C.size_t(len(args.BPFObjBuff))
392392

393393
if len(args.KConfigFilePath) <= 2 {
394-
C.free(unsafe.Pointer(cKconfigPath))
395394
cKconfigPath = nil
396395
}
397396

0 commit comments

Comments
 (0)