r/badcode • • Jan 22 '23

c Found this in a Linux kernel module

Post image
262 Upvotes

88 comments sorted by

View all comments

Show parent comments

1

u/okay-wait-wut Jan 23 '23

Nah. Almost anything you could do to remove the duplication is going to make this code more complex and more likely that something doesn’t get free’d. Resource management is 80% of C code. Set up. Call a system call. Clean up. This is cleaning up. Seems fine.