Skip to content

Commit e80d6ef

Browse files
committed
fix: memory issues for file monitoring
1 parent 9619039 commit e80d6ef

5 files changed

Lines changed: 10 additions & 14 deletions

File tree

CHANGELOG.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
[
1+
[ {
2+
"version": "0.3.1",
3+
"changes": ["Fix memory leak in file event handling"]
4+
},
25
{
36
"version": "0.3.0",
47
"changes": [

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.3.1

helpers/delete.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ static __always_inline int trace_file_delete(struct pt_regs *ctx, struct dentry
5252
bpf_core_read(&d_parent_flags, sizeof(d_parent_flags), &parent_de->d_flags);
5353
bpf_core_read(&d_flags, sizeof(d_flags), &de->d_flags);
5454
if ((d_parent_flags & DCACHE_NEGATIVE_DENTRY) || (d_flags & DCACHE_NEGATIVE_DENTRY)) {
55-
bpf_trace_printk("Negative dentry detected: parent flags: %u, dentry flags: %u\n", d_parent_flags, d_flags);
5655
DISCARD_AND_RETURN(data);
5756
}
5857

helpers/read_write.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,39 @@ static __always_inline int trace_file_operation(struct pt_regs *ctx, struct file
2323
bpf_core_read(&de, sizeof(de), &file->f_path.dentry);
2424
if (!de)
2525
{
26-
bpf_ringbuf_discard(data, 0);
27-
return 0;
26+
DISCARD_AND_RETURN(data);
2827
}
2928

3029
// Get filename
3130
struct qstr d_name = {};
3231
bpf_core_read(&d_name, sizeof(d_name), &de->d_name);
3332
if (d_name.len == 0)
3433
{
35-
bpf_ringbuf_discard(data, 0);
36-
return 0;
34+
DISCARD_AND_RETURN(data);
3735
}
3836

3937
// Get parent dentry
4038
struct dentry *parent_de = NULL;
4139
bpf_core_read(&parent_de, sizeof(parent_de), &de->d_parent);
4240
if (!parent_de)
4341
{
44-
bpf_ringbuf_discard(data, 0);
45-
return 0;
42+
DISCARD_AND_RETURN(data);
4643
}
4744

4845
// Get parent filename
4946
struct qstr parent_d_name = {};
5047
bpf_core_read(&parent_d_name, sizeof(parent_d_name), &parent_de->d_name);
5148
if (parent_d_name.len == 0)
5249
{
53-
bpf_ringbuf_discard(data, 0);
54-
return 0;
50+
DISCARD_AND_RETURN(data);
5551
}
5652

5753
// Get Inode from file structure
5854
struct inode *inode_ptr = NULL;
5955
bpf_core_read(&inode_ptr, sizeof(inode_ptr), &file->f_inode);
6056
if (!inode_ptr)
6157
{
62-
bpf_ringbuf_discard(data, 0);
63-
return 0;
58+
DISCARD_AND_RETURN(data);
6459
}
6560

6661
// Get the current cgroup ID

helpers/rename.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static __always_inline int trace_file_rename(
5858
bpf_core_read(&new_parent_flags, sizeof(new_parent_flags), &new_parent_de->d_flags);
5959
bpf_core_read(&old_parent_flags, sizeof(old_parent_flags), &old_parent_de->d_flags);
6060
if ((old_parent_flags & DCACHE_NEGATIVE_DENTRY) || (new_parent_flags & DCACHE_NEGATIVE_DENTRY)) {
61-
bpf_trace_printk("Negative dentry detected: old parent flags: %u, new parent flags: %u\n", old_parent_flags, new_parent_flags);
6261
DISCARD_AND_RETURN(data);
6362
}
6463

0 commit comments

Comments
 (0)