Permalink
Browse files

fixed the test t/obj.m1 and t/string.m1 in m1 repository

  • Loading branch information...
Jimmy Zhuo
Jimmy Zhuo committed Jun 8, 2012
1 parent 78d1d89 commit 2f4959f6a48050d5b1e2588fb8002142d414cbbe
Showing with 28 additions and 4 deletions.
  1. +22 −2 src/m0/c/interp.c
  2. +5 −1 src/m0/c/mob.c
  3. +1 −1 src/m0/c/ops.c
View
@@ -57,12 +57,14 @@ main( int argc, const char *argv[]) {
if (argc < 2) {
fprintf( stderr, "Usage: m0 <filename.mob>\n" );
interp_free( interp );
+ interp = NULL;
exit(1);
}
if (!load_mob_file( interp, argv[1] )) {
fprintf( stderr, "Could not load m0b file: '%s'\n", argv[1] );
interp_free( interp );
+ interp = NULL;
exit( 1 );
}
else {
@@ -71,6 +73,7 @@ main( int argc, const char *argv[]) {
call_frame_free( interp, cf );
interp_free( interp );
+ interp = NULL;
exit( 0 );
}
@@ -108,6 +111,7 @@ void
call_frame_free( M0_Interp *interp, M0_CallFrame *cf ) {
UNUSED(interp);
free( cf );
+ cf = NULL;
}
void
@@ -119,8 +123,10 @@ interp_free( M0_Interp *interp ) {
m0_chunk_free( chunk );
chunk = next;
}
- free( ((void *)(*interp)[CONFIG]) );
+ free( (void *)(*interp)[CONFIG] );
+ (*interp)[CONFIG] = NULL;
free( interp );
+ interp = NULL;
}
void
@@ -135,7 +141,10 @@ m0_chunk_free( M0_Chunk *chunk ) {
m0_chunk_free_bytecode( chunk->bytecode );
free( (char *)chunk->name );
+ chunk->name = NULL;
+
free( chunk );
+ chunk = NULL;
}
void
@@ -147,10 +156,14 @@ m0_chunk_free_constants( M0_Constants_Segment *constants )
for (i = 0; i < count; i++) {
if ( constants->consts[i] && constants->pointers[i])
free( (void *)constants->consts[i] );
+ constants->consts[i] = NULL;
}
free( constants->consts );
+ constants->consts = NULL;
+
free( constants );
+ constants = NULL;
}
void
@@ -162,19 +175,26 @@ m0_chunk_free_metadata( M0_Metadata_Segment *metadata )
for (i = 0; i < count; i++) {
if ( metadata->entries[i] )
free( (void *)metadata->entries[i] );
+ metadata->entries[i] = NULL;
}
free( metadata->entries );
+ metadata->entries = NULL;
+
free( metadata );
+ metadata = NULL;
}
void
m0_chunk_free_bytecode( M0_Bytecode_Segment *bytecode )
{
- if (bytecode->ops)
+ if (bytecode->ops) {
free( bytecode->ops );
+ bytecode->ops = NULL;
+ }
free( bytecode );
+ bytecode = NULL;
}
/* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
View
@@ -102,10 +102,12 @@ verify_mob_magic_number( M0_Interp *interp, FILE *stream ) {
if (strncmp( magic, header, 8 ) != 0) {
fprintf( stderr, "Invalid M0B header\n" );
free( magic );
+ magic = NULL;
return 0;
}
free( magic );
+ magic = NULL;
return 1;
}
@@ -229,7 +231,7 @@ parse_mob_constants_segment( M0_Interp *interp, FILE *stream ) {
const unsigned long str_length = length - 9;
char *p = malloc(str_length);
memcpy(p, &constant[8], str_length);
- free(constant);
+ free((void *)constant);
constant = p;
}
if (constant) {
@@ -239,7 +241,9 @@ parse_mob_constants_segment( M0_Interp *interp, FILE *stream ) {
} else {
if (constant)
segment->consts[i] = *(uint64_t *)constant;
+ segment->pointers[i] = 0;
free((void *)constant);
+ constant = NULL;
}
}
View
@@ -339,7 +339,7 @@ static void
m0_op_gc_alloc( M0_CallFrame *frame, const unsigned char *ops )
{
const int bytes = frame->registers[ops[2]];
- void *ptr = malloc( sizeof(char) * bytes );
+ void *ptr = malloc( sizeof(uint64_t) * bytes );
frame->registers[ops[1]] = (uint64_t) ptr;
}

0 comments on commit 2f4959f

Please sign in to comment.