Skip to content

Commit

Permalink
Use the new stream_malloc() function
Browse files Browse the repository at this point in the history
This updates all the malloc() users to use stream_malloc() instead.

This fixes the (missing) error handling paths in those callers.

Signed-off-by: Vegard Nossum <[email protected]>
  • Loading branch information
vegard committed May 17, 2009
1 parent 2a88f15 commit 2a5d6c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/cafebabe/attribute_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cafebabe_attribute_info_init(struct cafebabe_attribute_info *a,
if (cafebabe_stream_read_uint32(s, &a->attribute_length))
goto out;

a->info = malloc(a->attribute_length);
a->info = cafebabe_stream_malloc(s, a->attribute_length);
if (!a->info)
goto out;

Expand Down
17 changes: 10 additions & 7 deletions src/cafebabe/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ cafebabe_class_init(struct cafebabe_class *c, struct cafebabe_stream *s)
if (cafebabe_stream_read_uint16(s, &c->constant_pool_count))
goto out;

c->constant_pool = malloc(sizeof(*c->constant_pool)
* c->constant_pool_count);
c->constant_pool = cafebabe_stream_malloc(s,
sizeof(*c->constant_pool) * c->constant_pool_count);
if (!c->constant_pool)
goto out;

Expand Down Expand Up @@ -85,8 +85,8 @@ cafebabe_class_init(struct cafebabe_class *c, struct cafebabe_stream *s)
if (cafebabe_stream_read_uint16(s, &c->interfaces_count))
goto out_constant_pool_init;

c->interfaces = malloc(sizeof(*c->interfaces)
* c->interfaces_count);
c->interfaces = cafebabe_stream_malloc(s,
sizeof(*c->interfaces) * c->interfaces_count);
if (!c->interfaces)
goto out_constant_pool_init;

Expand All @@ -98,7 +98,8 @@ cafebabe_class_init(struct cafebabe_class *c, struct cafebabe_stream *s)
if (cafebabe_stream_read_uint16(s, &c->fields_count))
goto out_interfaces_alloc;

c->fields = malloc(sizeof(*c->fields) * c->fields_count);
c->fields = cafebabe_stream_malloc(s,
sizeof(*c->fields) * c->fields_count);
if (!c->fields)
goto out_interfaces_alloc;

Expand All @@ -114,7 +115,8 @@ cafebabe_class_init(struct cafebabe_class *c, struct cafebabe_stream *s)
if (cafebabe_stream_read_uint16(s, &c->methods_count))
goto out_fields_init;

c->methods = malloc(sizeof(*c->methods) * c->methods_count);
c->methods = cafebabe_stream_malloc(s,
sizeof(*c->methods) * c->methods_count);
if (!c->methods)
goto out_fields_init;

Expand All @@ -130,7 +132,8 @@ cafebabe_class_init(struct cafebabe_class *c, struct cafebabe_stream *s)
if (cafebabe_stream_read_uint16(s, &c->attributes_count))
goto out_methods_init;

c->attributes = malloc(sizeof(*c->attributes) * c->attributes_count);
c->attributes = cafebabe_stream_malloc(s,
sizeof(*c->attributes) * c->attributes_count);
if (!c->attributes)
goto out_methods_init;

Expand Down
7 changes: 2 additions & 5 deletions src/cafebabe/constant_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ cafebabe_constant_info_utf8_init(struct cafebabe_constant_info_utf8 *utf8,
if (cafebabe_stream_read_uint16(s, &utf8->length))
goto out;

utf8->bytes = malloc(utf8->length);
if (!utf8->bytes) {
s->syscall_errno = errno;
s->cafebabe_errno = CAFEBABE_ERROR_ERRNO;
utf8->bytes = cafebabe_stream_malloc(s, utf8->length);
if (!utf8->bytes)
goto out;
}

for (uint16_t i = 0; i < utf8->length; ++i) {
if (cafebabe_stream_read_uint8(s, &utf8->bytes[i]))
Expand Down
3 changes: 2 additions & 1 deletion src/cafebabe/field_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ cafebabe_field_info_init(struct cafebabe_field_info *f,
if (cafebabe_stream_read_uint16(s, &f->attributes_count))
goto out;

f->attributes = malloc(sizeof(*f->attributes) * f->attributes_count);
f->attributes = cafebabe_stream_malloc(s,
sizeof(*f->attributes) * f->attributes_count);
if (!f->attributes)
goto out;

Expand Down
3 changes: 2 additions & 1 deletion src/cafebabe/method_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ cafebabe_method_info_init(struct cafebabe_method_info *m,
if (cafebabe_stream_read_uint16(s, &m->attributes_count))
goto out;

m->attributes = malloc(sizeof(*m->attributes) * m->attributes_count);
m->attributes = cafebabe_stream_malloc(s,
sizeof(*m->attributes) * m->attributes_count);
if (!m->attributes)
goto out;

Expand Down

0 comments on commit 2a5d6c1

Please sign in to comment.