Various fixes for issues discovered by Claude#1190
Various fixes for issues discovered by Claude#1190vojtechtrefny merged 10 commits intostoraged-project:masterfrom
Conversation
The rename after cache pool creation was performed on failure (!ret) instead of on success (ret), unlike the analogous bd_lvm_thpool_convert which correctly uses (ret && name). This is clearly a typo. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The copy function assigned the dev pointer directly instead of duplicating the string. This causes a double-free when both the original and the copy are freed, since bd_nvdimm_namespace_info_free calls g_free on the dev field. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The .api file declared the parameter as BDLVMLVdata instead of BDLVMCacheStats. Also added the missing NULL check that all other free functions in the codebase have. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The copy function omitted the free_cluster_count field, so copies always had free_cluster_count = 0 regardless of the original value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The copy function skipped the total_devices field, so copies always had total_devices = 0 regardless of the original value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The get_device_info_from_match, get_subvolume_info_from_match, and get_filesystem_info_from_match functions used g_new (unzeroed) to allocate their return structs. If regex match groups return NULL, fields like size and used would contain uninitialized garbage values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When the SUBSYSTEM lookup fails, the function returned FALSE but the *label output parameter (already allocated earlier) was not freed, leaking the string. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When no namespaces are found, the function returned NULL without freeing the GPtrArray, leaking its memory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In bd_part_create_part, the error path for fdisk_get_partitions called fdisk_unref_partition(npa), but npa is not allocated until later. The call was harmless (fdisk handles NULL) but misleading dead code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In bd_crypto_tc_open, the context type validation error path called crypt_free(cd), but cd is not initialized until crypt_init is called further down. The call was harmless but misleading dead code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR includes bug fixes across plugin APIs and implementations, focusing on memory management (struct field copying, deep copies, cleanup on error paths), zero-initialization of allocated structs, control flow corrections, and enhanced test validation for cache operations. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/plugins/nvdimm.c (1)
567-571: Pre-existing issue: potential memory leak in error path.The error handling path uses
g_ptr_array_free(namespaces, FALSE)after manually freeing elements. WhenFALSEis passed,g_ptr_array_freereturns the underlying element array pointer, but this return value is discarded, potentially leaking that memory.Consider changing to
TRUEfor consistency with the fix at line 580:♻️ Suggested fix
if (!info) { g_ptr_array_foreach (namespaces, (GFunc) (void *) bd_nvdimm_namespace_info_free, NULL); - g_ptr_array_free (namespaces, FALSE); + g_ptr_array_free (namespaces, TRUE); ndctl_unref (ctx); return NULL; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/plugins/nvdimm.c` around lines 567 - 571, The error path frees each element via bd_nvdimm_namespace_info_free and then calls g_ptr_array_free(namespaces, FALSE) which discards the returned element array and leaks it; change the call to g_ptr_array_free(namespaces, TRUE) (in the block that also calls bd_nvdimm_namespace_info_free and ndctl_unref(ctx) and returns NULL) so the underlying array storage is freed as well, matching the later fix at the other return path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/plugins/lvm/lvm-dbus.c`:
- Around line 3717-3718: The code ignores bd_lvm_lvrename()'s return value
causing bd_lvm_cache_pool_convert() to report success even if the rename failed;
update the call in bd_lvm_cache_pool_convert so you capture and fold the rename
result into the existing status (e.g., set ret = ret && bd_lvm_lvrename(vg_name,
data_lv, name, NULL, error)) so the final return reflects both the
CreateCachePool and the LV rename outcome.
---
Nitpick comments:
In `@src/plugins/nvdimm.c`:
- Around line 567-571: The error path frees each element via
bd_nvdimm_namespace_info_free and then calls g_ptr_array_free(namespaces, FALSE)
which discards the returned element array and leaks it; change the call to
g_ptr_array_free(namespaces, TRUE) (in the block that also calls
bd_nvdimm_namespace_info_free and ndctl_unref(ctx) and returns NULL) so the
underlying array storage is freed as well, matching the later fix at the other
return path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 92a2b6f7-62de-4b4f-b3c6-7a97c630a5b6
📒 Files selected for processing (10)
src/lib/plugin_apis/fs.apisrc/lib/plugin_apis/lvm.apisrc/lib/plugin_apis/mdraid.apisrc/lib/plugin_apis/nvdimm.apisrc/plugins/btrfs.csrc/plugins/crypto.csrc/plugins/lvm/lvm-dbus.csrc/plugins/nvdimm.csrc/plugins/part.ctests/_lvm_cases.py
| if (ret && name) | ||
| bd_lvm_lvrename (vg_name, data_lv, name, NULL, error); |
There was a problem hiding this comment.
Propagate the rename result after a successful convert.
Line 3718 still ignores bd_lvm_lvrename()'s return value. If CreateCachePool succeeds but the rename fails, bd_lvm_cache_pool_convert() can still return TRUE even though the caller asked for a different final LV name. The native path in src/plugins/lvm/lvm.c:2499-2500 already folds the rename result into the final status.
Suggested fix
- if (ret && name)
- bd_lvm_lvrename (vg_name, data_lv, name, NULL, error);
+ if (ret && name)
+ ret = bd_lvm_lvrename (vg_name, data_lv, name, NULL, error);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (ret && name) | |
| bd_lvm_lvrename (vg_name, data_lv, name, NULL, error); | |
| if (ret && name) | |
| ret = bd_lvm_lvrename (vg_name, data_lv, name, NULL, error); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/plugins/lvm/lvm-dbus.c` around lines 3717 - 3718, The code ignores
bd_lvm_lvrename()'s return value causing bd_lvm_cache_pool_convert() to report
success even if the rename failed; update the call in bd_lvm_cache_pool_convert
so you capture and fold the rename result into the existing status (e.g., set
ret = ret && bd_lvm_lvrename(vg_name, data_lv, name, NULL, error)) so the final
return reflects both the CreateCachePool and the LV rename outcome.
Next batch, this time mostly in the .api files.
Summary by CodeRabbit
Bug Fixes