Fix memory leak when a JSON of model fails to parse #47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The valgrind test reports a memory leak for the example delete_pod
The reason is:
Deleting a pod successfully will return a
v1_pod_t
other than av1_status_t
from Kubernetes API server, but the generated client code still wants to parse the JSON string to create av1_status_t
in the functionv1_status_parseFromJSON
, the detail can refer to #31 (comment)v1_status_t *v1_status_parseFromJSON(cJSON *v1_statusJSON)
will return NULL because the parameterv1_statusJSON
is not a validv1_status_t
JSON, butmetadata_local_nonprim
(member of v1_status_t) is created and its memory is not released before the function returns, this will cause memory leak.I fixed the issue by this PR in the openapi-generator repo, now re-generate the C client to merge the fix.
After this fix, valgrind does not reports memory leak: