-
Notifications
You must be signed in to change notification settings - Fork 61
Fix issues discovered by static analysis #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues discovered by static analysis #1127
Conversation
Summary of ChangesHello @vojtechtrefny, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses several issues identified by static analysis tools, including Coverity, Clang, and GCC. The changes primarily focus on enhancing the robustness and error handling of the codebase. Key improvements include preventing null pointer dereferences during XFS filesystem parsing, ensuring proper error management when opening files for S390 device operations, and refining the thread-safe retrieval of Linux kernel version information. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses several issues found by static analysis tools by adding necessary checks and improving locking mechanisms. The added null checks in xfs.c
and s390.c
prevent potential crashes from dereferencing null pointers, which is a great improvement for robustness. The refactoring in module.c
correctly fixes a race condition and a potential deadlock related to fetching the Linux kernel version.
My review focuses on maintainability. While the fixes are correct, they introduce some code duplication in the error handling paths. I've left a couple of suggestions to refactor this duplicated code, which would make the functions easier to read and maintain in the long run. Overall, these are valuable fixes that improve the stability of the code.
if (!val_start) { | ||
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_PARSE, "Failed to parse xfs file system information"); | ||
g_strfreev (lines); | ||
bd_fs_xfs_info_free (ret); | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding this null check is crucial for correctness, the error handling logic is now duplicated in multiple places within this function (e.g., lines 401-406, 412-417, 430-435, and also in existing code). This makes the code harder to maintain and prone to errors if a cleanup path is modified in one place but not others.
Consider refactoring to use a single cleanup point with goto
. This is a common and idiomatic pattern in C for handling resource cleanup and would centralize the logic, reduce duplication, and improve readability.
if (!fd) { | ||
g_set_error (&l_error, BD_S390_ERROR, BD_S390_ERROR_DEVICE, | ||
"Failed to open %s", hba_path); | ||
g_free (hba_path); | ||
g_free (fcpsysfs); | ||
g_free (scsidev); | ||
bd_utils_report_finished (progress_id, l_error->message); | ||
g_propagate_error (error, l_error); | ||
return FALSE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error handling logic is very similar in the three blocks you've added (here, and at lines 822-832, 853-864) and also resembles other error paths in this function. This leads to a lot of duplicated code, which is difficult to maintain. Since this function deals with many allocated resources inside a loop, consider refactoring to centralize cleanup. A common C idiom is to use goto
to a cleanup label.
Multiple issues found by coverity and clang/gcc static analysis tools.
41758bd
to
93fb206
Compare
Multiple issues found by coverity and clang/gcc static analysis tools.