fix c-libcurl generator for int and boolean values by moving to int*#23052
fix c-libcurl generator for int and boolean values by moving to int*#23052hirishh wants to merge 6 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
24 issues found across 37 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/c-useJsonUnformatted/model/tag.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/tag.c:20">
P2: Allocation failure path leaks tag_local_var because tag_free returns early before _library_owned is set.</violation>
<violation number="2" location="samples/client/petstore/c-useJsonUnformatted/model/tag.c:126">
P2: Memory leak: tag_parseFromJSON allocates id_local_var, but tag_create_internal copies the value into a new allocation and does not take ownership, so id_local_var is never freed on the success path.</violation>
</file>
<file name="samples/client/petstore/c/model/pet.c">
<violation number="1" location="samples/client/petstore/c/model/pet.c:41">
P2: Calling pet_free before _library_owned is set causes an early return, leaking pet_local_var on id allocation failure.</violation>
<violation number="2" location="samples/client/petstore/c/model/pet.c:225">
P2: id_local_var is allocated in pet_parseFromJSON and passed to pet_create_internal, which copies it into a new allocation; the original id_local_var is never freed on the success path, leaking memory each parse.</violation>
</file>
<file name="samples/client/petstore/c/model/api_response.c">
<violation number="1" location="samples/client/petstore/c/model/api_response.c:21">
P2: Allocation failure leaks api_response_local_var because api_response_free returns early when _library_owned is still zeroed.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache:212">
P2: Allocation failure path now calls {{classname}}_free before _library_owned is set, so cleanup is skipped and the partially built object leaks.</violation>
<violation number="2" location="modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache:784">
P2: Temporary numeric/boolean allocations in parseFromJSON are never freed on success; create_internal copies values into newly allocated memory, leaving name_local_var leaked.</violation>
</file>
<file name="samples/client/petstore/c-useJsonUnformatted/model/api_response.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/api_response.c:21">
P2: Leak on code allocation failure because api_response_free returns early before _library_owned is set.</violation>
<violation number="2" location="samples/client/petstore/c-useJsonUnformatted/model/api_response.c:120">
P2: code_local_var is allocated in api_response_parseFromJSON but never freed on the success path after api_response_create_internal copies the value, causing a memory leak for each parsed response with a code.</violation>
</file>
<file name="samples/client/petstore/c-useJsonUnformatted/model/order.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/order.c:41">
P2: Allocation failure calls order_free before _library_owned is set, so order_free returns early and leaks the partially allocated order object and fields.</violation>
</file>
<file name="samples/client/petstore/c-useJsonUnformatted/model/category.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/category.c:20">
P2: Leak on id allocation failure: category_free returns early because _library_owned is still 0, so category_local_var is not freed on this error path.</violation>
<violation number="2" location="samples/client/petstore/c-useJsonUnformatted/model/category.c:126">
P2: id_local_var is allocated in category_parseFromJSON and passed to category_create_internal, which copies the value into a new allocation. The original id_local_var is never freed on the success path, so each successful parse leaks memory.</violation>
</file>
<file name="samples/client/petstore/c/model/user.c">
<violation number="1" location="samples/client/petstore/c/model/user.c:28">
P2: user_free is called on allocation failure before _library_owned is set, so user_free returns early and leaks user_local_var (and any allocated fields) on those error paths.</violation>
</file>
<file name="samples/client/petstore/c/model/order.c">
<violation number="1" location="samples/client/petstore/c/model/order.c:37">
P2: Allocation failure paths call order_free before _library_owned is set, so order_free returns early and leaks order_local_var (and any allocated fields).</violation>
<violation number="2" location="samples/client/petstore/c/model/order.c:212">
P2: Temporary allocations in order_parseFromJSON are leaked on success: id/pet_id/quantity/complete are heap-allocated, order_create_internal copies their values into new allocations, and the locals are never freed before returning on the success path.</violation>
</file>
<file name="samples/client/petstore/c-useJsonUnformatted/model/pet.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/pet.c:41">
P2: pet_create_internal calls pet_free before _library_owned is set, so pet_free early-returns and leaks pet_local_var on id allocation failure.</violation>
<violation number="2" location="samples/client/petstore/c-useJsonUnformatted/model/pet.c:225">
P2: `id_local_var` is heap-allocated in `pet_parseFromJSON` and passed to `pet_create_internal`, which copies it into a new allocation. The original allocation is never freed on the success path (or when create returns NULL), causing a leak.</violation>
</file>
<file name="samples/client/petstore/c-useJsonUnformatted/model/user.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/user.c:28">
P3: user_free is invoked on allocation failures before _library_owned is set, so user_free returns early and leaks user_local_var (and any assigned fields) on those error paths.</violation>
</file>
<file name="samples/client/petstore/c-useJsonUnformatted/model/mapped_model.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/mapped_model.c:20">
P2: Error path leak: MappedModel_free returns early because _library_owned is still 0 when another_property allocation fails, so the allocated struct is never freed.</violation>
<violation number="2" location="samples/client/petstore/c-useJsonUnformatted/model/mapped_model.c:126">
P2: Memory leak: another_property_local_var allocated in parseFromJSON is not freed on the success path after MappedModel_create_internal copies the value into a new allocation.</violation>
</file>
<file name="samples/client/petstore/c/model/mapped_model.c">
<violation number="1" location="samples/client/petstore/c/model/mapped_model.c:20">
P3: Allocation failure path leaks MappedModel_local_var because MappedModel_free returns early when _library_owned is still 0.</violation>
<violation number="2" location="samples/client/petstore/c/model/mapped_model.c:104">
P2: Temporary allocation `another_property_local_var` in `MappedModel_parseFromJSON` is never freed on the success path. Since `MappedModel_create_internal` makes its own heap copy, this allocation leaks on every successful parse.</violation>
</file>
<file name="samples/client/petstore/c/model/tag.c">
<violation number="1" location="samples/client/petstore/c/model/tag.c:20">
P2: Leak on id allocation failure: tag_free returns early because _library_owned is still 0, so tag_local_var is never freed.</violation>
<violation number="2" location="samples/client/petstore/c/model/tag.c:104">
P2: id_local_var is allocated in tag_parseFromJSON and passed to tag_create_internal, which now copies it into a new allocation. The original id_local_var is never freed on success, causing a memory leak.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
@cubic-dev-ai re-run a review |
@hirishh I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
4 issues found across 37 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/c-useJsonUnformatted/model/tag.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/tag.c:123">
P2: tag_parseFromJSON leaks id_local_var and the duplicated name when tag_create_internal fails, because there’s no NULL check and cleanup after the call.</violation>
</file>
<file name="samples/client/petstore/c-useJsonUnformatted/model/category.c">
<violation number="1" location="samples/client/petstore/c-useJsonUnformatted/model/category.c:123">
P3: Memory leak on category_create_internal failure: id_local_var and duplicated name are not freed if allocation of category_local_var fails.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache:295">
P2: {{classname}}_create allocates numeric/boolean copies but never frees them if {{classname}}_create_internal fails, causing a leak on allocation failure.</violation>
<violation number="2" location="modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache:782">
P2: {{classname}}_parseFromJSON returns immediately after {{classname}}_create_internal without freeing allocated numeric/boolean locals if the create fails, leaking memory on allocation failure.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache
Show resolved
Hide resolved
|
@cubic-dev-ai re-run a review again :) (you are a smart ai bot) |
@hirishh I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
3 issues found across 37 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/c/model/api_response.c">
<violation number="1" location="samples/client/petstore/c/model/api_response.c:160">
P2: Error path leaks the strdup’d type/message strings when api_response_create_internal fails; only code_local_var is freed at end.</violation>
</file>
<file name="samples/client/petstore/c/model/category.c">
<violation number="1" location="samples/client/petstore/c/model/category.c:131">
P2: Memory leak: on category_create_internal failure, the strdup’d name is not freed before jumping to end, so the allocation leaks.</violation>
</file>
<file name="samples/client/petstore/c/model/pet.c">
<violation number="1" location="samples/client/petstore/c/model/pet.c:331">
P2: Memory leak on error path: strdup(name->valuestring) is not freed if pet_create_internal fails and goto end is taken.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
@cubic-dev-ai re-run a review |
@hirishh I have started the AI code review. It will take a few minutes to complete. |
61bb901 to
f79341f
Compare
|
@cubic-dev-ai re-run a review |
@hirishh I have started the AI code review. It will take a few minutes to complete. |
This is a follow up PR about #15782
FYI C coommittee @zhemant (2018/11) @ityuhui (2019/12) @michelealbano (2020/03)
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Switch C-libcurl model generation to int*/long*/bool* for optional fields, with deep-copying in create(), pointer dereferencing in JSON, and full error‑path cleanup to resolve memory leaks. Regenerated petstore samples (c and useJsonUnformatted) and fixed manual unit tests.
Bug Fixes
Migration
Written for commit f79341f. Summary will update on new commits.