Bug Summary

File:model/tag.c
Warning:line 84, column 19
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 tag.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/tag.c
1#include <stdlib.h>
2#include <string.h>
3#include <stdio.h>
4#include "tag.h"
5
6
7
8tag_t *tag_create(
9 long id,
10 char *name
11 ) {
12 tag_t *tag_local_var = malloc(sizeof(tag_t));
13 if (!tag_local_var) {
14 return NULL((void*)0);
15 }
16 tag_local_var->id = id;
17 tag_local_var->name = name;
18
19 return tag_local_var;
20}
21
22
23void tag_free(tag_t *tag) {
24 if(NULL((void*)0) == tag){
25 return ;
26 }
27 listEntry_t *listEntry;
28 if (tag->name) {
29 free(tag->name);
30 tag->name = NULL((void*)0);
31 }
32 free(tag);
33}
34
35cJSON *tag_convertToJSON(tag_t *tag) {
36 cJSON *item = cJSON_CreateObject();
37
38 // tag->id
39 if(tag->id) {
40 if(cJSON_AddNumberToObject(item, "id", tag->id) == NULL((void*)0)) {
41 goto fail; //Numeric
42 }
43 }
44
45
46 // tag->name
47 if(tag->name) {
48 if(cJSON_AddStringToObject(item, "name", tag->name) == NULL((void*)0)) {
49 goto fail; //String
50 }
51 }
52
53 return item;
54fail:
55 if (item) {
56 cJSON_Delete(item);
57 }
58 return NULL((void*)0);
59}
60
61tag_t *tag_parseFromJSON(cJSON *tagJSON){
62
63 tag_t *tag_local_var = NULL((void*)0);
64
65 // tag->id
66 cJSON *id = cJSON_GetObjectItemCaseSensitive(tagJSON, "id");
67 if (id) {
1
Assuming 'id' is null
2
Taking false branch
68 if(!cJSON_IsNumber(id))
69 {
70 goto end; //Numeric
71 }
72 }
73
74 // tag->name
75 cJSON *name = cJSON_GetObjectItemCaseSensitive(tagJSON, "name");
76 if (name) {
3
Assuming 'name' is non-null
4
Taking true branch
77 if(!cJSON_IsString(name))
5
Assuming the condition is false
6
Taking false branch
78 {
79 goto end; //String
80 }
81 }
82
83
84 tag_local_var = tag_create (
10
Potential memory leak
85
6.1
'id' is null
id ? id->valuedouble : 0,
7
'?' condition is false
86
7.1
'name' is non-null
name ? strdup(name->valuestring) : NULL((void*)0)
8
'?' condition is true
9
Memory is allocated
87 );
88
89 return tag_local_var;
90end:
91 return NULL((void*)0);
92
93}