|
17 | 17 | #include <string.h> |
18 | 18 |
|
19 | 19 | #include "upb/base/descriptor_constants.h" |
| 20 | +#include "upb/mem/alloc.h" |
20 | 21 | #include "upb/message/array.h" |
21 | 22 | #include "upb/message/map.h" |
22 | 23 | #include "upb/message/message.h" |
@@ -168,10 +169,12 @@ static void upb_FieldPathVector_Reserve(upb_FindContext* ctx, |
168 | 169 | upb_FieldPathVector* vec, |
169 | 170 | size_t elems) { |
170 | 171 | if (vec->cap - vec->size < elems) { |
| 172 | + const int oldsize = vec->cap * sizeof(*vec->path); |
171 | 173 | size_t need = vec->size + elems; |
172 | 174 | vec->cap = UPB_MAX(4, vec->cap); |
173 | 175 | while (vec->cap < need) vec->cap *= 2; |
174 | | - vec->path = realloc(vec->path, vec->cap * sizeof(*vec->path)); |
| 176 | + const int newsize = vec->cap * sizeof(*vec->path); |
| 177 | + vec->path = upb_grealloc(vec->path, oldsize, newsize); |
175 | 178 | if (!vec->path) { |
176 | 179 | UPB_LONGJMP(ctx->err, 1); |
177 | 180 | } |
@@ -289,7 +292,7 @@ bool upb_util_HasUnsetRequired(const upb_Message* msg, const upb_MessageDef* m, |
289 | 292 | upb_FieldPathVector_Init(&ctx.stack); |
290 | 293 | upb_FieldPathVector_Init(&ctx.out_fields); |
291 | 294 | upb_util_FindUnsetRequiredInternal(&ctx, msg, m); |
292 | | - free(ctx.stack.path); |
| 295 | + upb_gfree(ctx.stack.path); |
293 | 296 |
|
294 | 297 | if (ctx.has_unset_required && fields) { |
295 | 298 | upb_FieldPathVector_Reserve(&ctx, &ctx.out_fields, 1); |
|
0 commit comments