Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
json-editor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IOPSYS
json-editor
Commits
4811f0b0
Commit
4811f0b0
authored
5 years ago
by
Jakob Olsson
Browse files
Options
Downloads
Patches
Plain Diff
fix memory leaks
parent
cbaec2e5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api.c
+10
-7
10 additions, 7 deletions
api.c
test/api_test.c
+7
-0
7 additions, 0 deletions
test/api_test.c
with
17 additions
and
7 deletions
api.c
+
10
−
7
View file @
4811f0b0
...
...
@@ -31,7 +31,7 @@ static char *get_file(const char *path)
if
(
fseek
(
f
,
0
,
SEEK_SET
))
goto
out_close
;
buffer
=
calloc
(
1
,
len
);
buffer
=
calloc
(
1
,
len
+
1
);
if
(
!
buffer
)
goto
out_close
;
...
...
@@ -170,12 +170,13 @@ struct json_object *dummy_val(char *val, enum json_type type)
return
j_val
;
}
int
add_array
(
struct
json_object
*
ptr
,
int
*
idx
,
int
len
,
char
*
val
,
enum
json_type
type
,
char
*
key
)
int
add_array
(
struct
json_object
*
ptr
,
int
*
idx
,
int
len
,
struct
json_object
*
j_
val
,
enum
json_type
type
,
char
*
key
)
{
struct
json_object
*
tmp
,
*
tmp1
;
struct
json_object
*
j_val
;
j_val
=
dummy_val
(
val
,
type
);
if
(
len
<
1
)
return
-
1
;
if
(
!
j_val
)
return
-
1
;
json_object_object_get_ex
(
ptr
,
key
,
&
tmp
);
...
...
@@ -220,6 +221,7 @@ int add_val(struct json_object *ptr, char *key, char *val, enum json_type type)
j_val
=
dummy_val
(
val
,
type
);
if
(
!
j_val
||
!
json_object_is_type
(
j_val
,
type
))
{
fprintf
(
stderr
,
"Invalid input value, parsed value and input type does not match!
\n
"
);
json_object_put
(
j_val
);
return
-
1
;
}
...
...
@@ -231,12 +233,13 @@ int add_val(struct json_object *ptr, char *key, char *val, enum json_type type)
ptr
=
json_object_new_object
();
json_object_object_foreach
(
j_val
,
key1
,
val1
)
json_object_object_add
(
ptr
,
key1
,
val1
);
json_object_object_add
(
ptr
,
key1
,
json_object_get
(
val1
)
)
;
if
(
key
)
{
json_object_object_add
(
tmp
,
parsed_key
,
ptr
);
}
json_object_put
(
j_val
);
}
else
{
add_array
(
ptr
,
idx
,
len
,
val
,
type
,
parsed_key
);
add_array
(
ptr
,
idx
,
len
,
j_
val
,
type
,
parsed_key
);
}
return
0
;
...
...
@@ -245,7 +248,7 @@ int add_val(struct json_object *ptr, char *key, char *val, enum json_type type)
if
(
len
<
1
||
type
==
json_type_array
)
json_object_object_add
(
ptr
,
parsed_key
,
j_val
);
else
{
add_array
(
ptr
,
idx
,
len
,
val
,
type
,
parsed_key
);
add_array
(
ptr
,
idx
,
len
,
j_
val
,
type
,
parsed_key
);
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
test/api_test.c
+
7
−
0
View file @
4811f0b0
...
...
@@ -15,6 +15,8 @@ static void test_cfg_parse_success(void **state)
struct
json_object
*
file
=
json_object_file_to_obj
(
"test.json"
);
assert_non_null
(
file
);
struct
json_object
*
obj
=
json_object_new_object
();
struct
json_object
*
tot
=
json_object_new_object
();
...
...
@@ -43,6 +45,8 @@ static void test_build_from_scratch(void **state)
struct
json_object
*
file
=
json_object_file_to_obj
(
"test.json"
);
struct
json_object
*
jobj
=
NULL
;
assert_non_null
(
file
);
json_object_set_by_string
(
&
jobj
,
NULL
,
"{\
\"
test
\"
:
\"
success
\"
,\
...
...
@@ -71,6 +75,8 @@ static void test_build_from_scratch(void **state)
printf
(
"modify_obj=%s
\n
"
,
json_object_get_string
(
jobj
));
assert_int_equal
(
1
,
json_object_equal
(
file
,
jobj
));
json_object_put
(
jobj
);
json_object_put
(
file
);
}
static
void
test_json_set_object
(
void
**
state
)
...
...
@@ -511,6 +517,7 @@ static void test_json_write_to_file(void **state)
obj
=
json_object_file_to_obj
(
"cpy.json"
);
assert_int_equal
(
1
,
json_object_equal
(
file_obj
,
obj
));
json_object_put
(
obj
);
}
int
main
(
void
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment