Bug Summary

File:model/api_response.c
Warning:line 107, column 28
Potential memory leak

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name api_response.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/llvm-9/lib/clang/9.0.0 -D openapi_petstore_EXPORTS -I /usr/local/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/wing328/Code/openapi-generator/samples/client/petstore/c -ferror-limit 19 -fmessage-length 0 -fvisibility default -fobjc-runtime=gcc -fdiagnostics-show-option -analyzer-output=html -faddrsig -o /tmp/scan-build-2020-12-16-230944-1865-1 -x c /home/wing328/Code/openapi-generator/samples/client/petstore/c/model/api_response.c
1#include <stdlib.h>
2#include <string.h>
3#include <stdio.h>
4#include "api_response.h"
5
6
7
8api_response_t *api_response_create(
9 int code,
10 char *type,
11 char *message
12 ) {
13 api_response_t *api_response_local_var = malloc(sizeof(api_response_t));
14 if (!api_response_local_var) {
15 return NULL((void*)0);
16 }
17 api_response_local_var->code = code;
18 api_response_local_var->type = type;
19 api_response_local_var->message = message;
20
21 return api_response_local_var;
22}
23
24
25void api_response_free(api_response_t *api_response) {
26 if(NULL((void*)0) == api_response){
27 return ;
28 }
29 listEntry_t *listEntry;
30 if (api_response->type) {
31 free(api_response->type);
32 api_response->type = NULL((void*)0);
33 }
34 if (api_response->message) {
35 free(api_response->message);
36 api_response->message = NULL((void*)0);
37 }
38 free(api_response);
39}
40
41cJSON *api_response_convertToJSON(api_response_t *api_response) {
42 cJSON *item = cJSON_CreateObject();
43
44 // api_response->code
45 if(api_response->code) {
46 if(cJSON_AddNumberToObject(item, "code", api_response->code) == NULL((void*)0)) {
47 goto fail; //Numeric
48 }
49 }
50
51
52 // api_response->type
53 if(api_response->type) {
54 if(cJSON_AddStringToObject(item, "type", api_response->type) == NULL((void*)0)) {
55 goto fail; //String
56 }
57 }
58
59
60 // api_response->message
61 if(api_response->message) {
62 if(cJSON_AddStringToObject(item, "message", api_response->message) == NULL((void*)0)) {
63 goto fail; //String
64 }
65 }
66
67 return item;
68fail:
69 if (item) {
70 cJSON_Delete(item);
71 }
72 return NULL((void*)0);
73}
74
75api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){
76
77 api_response_t *api_response_local_var = NULL((void*)0);
78
79 // api_response->code
80 cJSON *code = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "code");
81 if (code) {
1
Assuming 'code' is null
2
Taking false branch
82 if(!cJSON_IsNumber(code))
83 {
84 goto end; //Numeric
85 }
86 }
87
88 // api_response->type
89 cJSON *type = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "type");
90 if (type) {
3
Assuming 'type' is null
4
Taking false branch
91 if(!cJSON_IsString(type))
92 {
93 goto end; //String
94 }
95 }
96
97 // api_response->message
98 cJSON *message = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "message");
99 if (message) {
5
Assuming 'message' is non-null
6
Taking true branch
100 if(!cJSON_IsString(message))
7
Assuming the condition is false
8
Taking false branch
101 {
102 goto end; //String
103 }
104 }
105
106
107 api_response_local_var = api_response_create (
13
Potential memory leak
108
8.1
'code' is null
code ? code->valuedouble : 0,
9
'?' condition is false
109
9.1
'type' is null
type ? strdup(type->valuestring) : NULL((void*)0),
10
'?' condition is false
110
10.1
'message' is non-null
message ? strdup(message->valuestring) : NULL((void*)0)
11
'?' condition is true
12
Memory is allocated
111 );
112
113 return api_response_local_var;
114end:
115 return NULL((void*)0);
116
117}