Bug Summary

File:model/user.c
Warning:line 218, column 20
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 user.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/user.c
1#include <stdlib.h>
2#include <string.h>
3#include <stdio.h>
4#include "user.h"
5
6
7
8user_t *user_create(
9 long id,
10 char *username,
11 char *first_name,
12 char *last_name,
13 char *email,
14 char *password,
15 char *phone,
16 int user_status
17 ) {
18 user_t *user_local_var = malloc(sizeof(user_t));
19 if (!user_local_var) {
20 return NULL((void*)0);
21 }
22 user_local_var->id = id;
23 user_local_var->username = username;
24 user_local_var->first_name = first_name;
25 user_local_var->last_name = last_name;
26 user_local_var->email = email;
27 user_local_var->password = password;
28 user_local_var->phone = phone;
29 user_local_var->user_status = user_status;
30
31 return user_local_var;
32}
33
34
35void user_free(user_t *user) {
36 if(NULL((void*)0) == user){
37 return ;
38 }
39 listEntry_t *listEntry;
40 if (user->username) {
41 free(user->username);
42 user->username = NULL((void*)0);
43 }
44 if (user->first_name) {
45 free(user->first_name);
46 user->first_name = NULL((void*)0);
47 }
48 if (user->last_name) {
49 free(user->last_name);
50 user->last_name = NULL((void*)0);
51 }
52 if (user->email) {
53 free(user->email);
54 user->email = NULL((void*)0);
55 }
56 if (user->password) {
57 free(user->password);
58 user->password = NULL((void*)0);
59 }
60 if (user->phone) {
61 free(user->phone);
62 user->phone = NULL((void*)0);
63 }
64 free(user);
65}
66
67cJSON *user_convertToJSON(user_t *user) {
68 cJSON *item = cJSON_CreateObject();
69
70 // user->id
71 if(user->id) {
72 if(cJSON_AddNumberToObject(item, "id", user->id) == NULL((void*)0)) {
73 goto fail; //Numeric
74 }
75 }
76
77
78 // user->username
79 if(user->username) {
80 if(cJSON_AddStringToObject(item, "username", user->username) == NULL((void*)0)) {
81 goto fail; //String
82 }
83 }
84
85
86 // user->first_name
87 if(user->first_name) {
88 if(cJSON_AddStringToObject(item, "firstName", user->first_name) == NULL((void*)0)) {
89 goto fail; //String
90 }
91 }
92
93
94 // user->last_name
95 if(user->last_name) {
96 if(cJSON_AddStringToObject(item, "lastName", user->last_name) == NULL((void*)0)) {
97 goto fail; //String
98 }
99 }
100
101
102 // user->email
103 if(user->email) {
104 if(cJSON_AddStringToObject(item, "email", user->email) == NULL((void*)0)) {
105 goto fail; //String
106 }
107 }
108
109
110 // user->password
111 if(user->password) {
112 if(cJSON_AddStringToObject(item, "password", user->password) == NULL((void*)0)) {
113 goto fail; //String
114 }
115 }
116
117
118 // user->phone
119 if(user->phone) {
120 if(cJSON_AddStringToObject(item, "phone", user->phone) == NULL((void*)0)) {
121 goto fail; //String
122 }
123 }
124
125
126 // user->user_status
127 if(user->user_status) {
128 if(cJSON_AddNumberToObject(item, "userStatus", user->user_status) == NULL((void*)0)) {
129 goto fail; //Numeric
130 }
131 }
132
133 return item;
134fail:
135 if (item) {
136 cJSON_Delete(item);
137 }
138 return NULL((void*)0);
139}
140
141user_t *user_parseFromJSON(cJSON *userJSON){
142
143 user_t *user_local_var = NULL((void*)0);
144
145 // user->id
146 cJSON *id = cJSON_GetObjectItemCaseSensitive(userJSON, "id");
147 if (id) {
1
Assuming 'id' is null
2
Taking false branch
148 if(!cJSON_IsNumber(id))
149 {
150 goto end; //Numeric
151 }
152 }
153
154 // user->username
155 cJSON *username = cJSON_GetObjectItemCaseSensitive(userJSON, "username");
156 if (username) {
3
Assuming 'username' is null
4
Taking false branch
157 if(!cJSON_IsString(username))
158 {
159 goto end; //String
160 }
161 }
162
163 // user->first_name
164 cJSON *first_name = cJSON_GetObjectItemCaseSensitive(userJSON, "firstName");
165 if (first_name) {
5
Assuming 'first_name' is null
6
Taking false branch
166 if(!cJSON_IsString(first_name))
167 {
168 goto end; //String
169 }
170 }
171
172 // user->last_name
173 cJSON *last_name = cJSON_GetObjectItemCaseSensitive(userJSON, "lastName");
174 if (last_name) {
7
Assuming 'last_name' is null
8
Taking false branch
175 if(!cJSON_IsString(last_name))
176 {
177 goto end; //String
178 }
179 }
180
181 // user->email
182 cJSON *email = cJSON_GetObjectItemCaseSensitive(userJSON, "email");
183 if (email) {
9
Assuming 'email' is null
10
Taking false branch
184 if(!cJSON_IsString(email))
185 {
186 goto end; //String
187 }
188 }
189
190 // user->password
191 cJSON *password = cJSON_GetObjectItemCaseSensitive(userJSON, "password");
192 if (password) {
11
Assuming 'password' is null
12
Taking false branch
193 if(!cJSON_IsString(password))
194 {
195 goto end; //String
196 }
197 }
198
199 // user->phone
200 cJSON *phone = cJSON_GetObjectItemCaseSensitive(userJSON, "phone");
201 if (phone) {
13
Assuming 'phone' is non-null
14
Taking true branch
202 if(!cJSON_IsString(phone))
15
Assuming the condition is false
16
Taking false branch
203 {
204 goto end; //String
205 }
206 }
207
208 // user->user_status
209 cJSON *user_status = cJSON_GetObjectItemCaseSensitive(userJSON, "userStatus");
210 if (user_status) {
17
Assuming 'user_status' is null
18
Taking false branch
211 if(!cJSON_IsNumber(user_status))
212 {
213 goto end; //Numeric
214 }
215 }
216
217
218 user_local_var = user_create (
28
Potential memory leak
219
18.1
'id' is null
id ? id->valuedouble : 0,
19
'?' condition is false
220
19.1
'username' is null
username ? strdup(username->valuestring) : NULL((void*)0),
20
'?' condition is false
221
20.1
'first_name' is null
first_name ? strdup(first_name->valuestring) : NULL((void*)0),
21
'?' condition is false
222
21.1
'last_name' is null
last_name ? strdup(last_name->valuestring) : NULL((void*)0),
22
'?' condition is false
223
22.1
'email' is null
email ? strdup(email->valuestring) : NULL((void*)0),
23
'?' condition is false
224
23.1
'password' is null
password ? strdup(password->valuestring) : NULL((void*)0),
24
'?' condition is false
225
24.1
'phone' is non-null
phone ? strdup(phone->valuestring) : NULL((void*)0),
25
'?' condition is true
26
Memory is allocated
226
26.1
'user_status' is null
user_status ? user_status->valuedouble : 0
27
'?' condition is false
227 );
228
229 return user_local_var;
230end:
231 return NULL((void*)0);
232
233}