Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Adds missing frees of string objects
Browse files Browse the repository at this point in the history
Signed-off-by: ncordon <[email protected]>
  • Loading branch information
ncordon authored and dennwc committed Jul 29, 2019
1 parent e846a45 commit c8abc78
Showing 1 changed file with 44 additions and 36 deletions.
80 changes: 44 additions & 36 deletions src/uast.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,43 +119,51 @@ static NodeHandle UastLoad(const Uast *src, NodeHandle n, const Uast *dst) {
if (kind == NODE_NULL) {
return 0;
} else if (kind == NODE_OBJECT) {
size_t sz = UAST_CALL(src, Size, n);

NodeHandle m = UAST_CALL(dst, NewObject, sz);
size_t i;
for (i = 0; i < sz; i++) {
const char * k = UAST_CALL(src, KeyAt, n, i);
if (!k) {
return 0;
}
NodeHandle v = UAST_CALL(src, ValueAt, n, i);
v = UastLoad(src, v, dst);
UAST_CALL(dst, SetKeyValue, m, k, v);
}
return m;
} else if (kind == NODE_ARRAY) {
size_t sz = UAST_CALL(src, Size, n);

NodeHandle m = UAST_CALL(dst, NewArray, sz);
size_t i;
for (i = 0; i < sz; i++) {
NodeHandle v = UAST_CALL(src, ValueAt, n, i);
v = UastLoad(src, v, dst);
UAST_CALL(dst, SetValue, m, i, v);
size_t sz = UAST_CALL(src, Size, n);

NodeHandle m = UAST_CALL(dst, NewObject, sz);
size_t i;

for (i = 0; i < sz; i++) {
char* k = UAST_CALL(src, KeyAt, n, i);

if (!k) {
return 0;
}
return m;
} else if (kind == NODE_STRING) {
return UAST_CALL(dst, NewString, UAST_CALL(src, AsString, n));
} else if (kind == NODE_INT) {
return UAST_CALL(dst, NewInt, UAST_CALL(src, AsInt, n));
} else if (kind == NODE_UINT) {
return UAST_CALL(dst, NewUint, UAST_CALL(src, AsUint, n));
} else if (kind == NODE_FLOAT) {
return UAST_CALL(dst, NewFloat, UAST_CALL(src, AsFloat, n));
} else if (kind == NODE_BOOL) {
return UAST_CALL(dst, NewBool, UAST_CALL(src, AsBool, n));

NodeHandle v = UAST_CALL(src, ValueAt, n, i);
v = UastLoad(src, v, dst);
UAST_CALL(dst, SetKeyValue, m, k, v);
free(k);
}
return m;
} else if (kind == NODE_ARRAY) {
size_t sz = UAST_CALL(src, Size, n);

NodeHandle m = UAST_CALL(dst, NewArray, sz);
size_t i;
for (i = 0; i < sz; i++) {
NodeHandle v = UAST_CALL(src, ValueAt, n, i);
v = UastLoad(src, v, dst);
UAST_CALL(dst, SetValue, m, i, v);
}
return 0;
return m;
} else if (kind == NODE_STRING) {
char *s = UAST_CALL(src, AsString, n);
NodeHandle m = UAST_CALL(dst, NewString, s);
free(s);
return m;
} else if (kind == NODE_INT) {
return UAST_CALL(dst, NewInt, UAST_CALL(src, AsInt, n));
} else if (kind == NODE_UINT) {
return UAST_CALL(dst, NewUint, UAST_CALL(src, AsUint, n));
} else if (kind == NODE_FLOAT) {
return UAST_CALL(dst, NewFloat, UAST_CALL(src, AsFloat, n));
} else if (kind == NODE_BOOL) {
return UAST_CALL(dst, NewBool, UAST_CALL(src, AsBool, n));
}

return 0;
}

// UastMemStats holds memory statistics for libuast.
Expand All @@ -178,4 +186,4 @@ typedef struct UastLineCol {

/*GO-HEADER*/

#endif // UAST_H_
#endif // UAST_H_

0 comments on commit c8abc78

Please sign in to comment.