summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Herlant <herlantj@gmail.com>2018-04-02 18:20:37 -0700
committerJoseph Herlant <herlantj@gmail.com>2018-04-02 18:20:37 -0700
commitab945bdc1a75f8d6568b7a00a46698de8427878e (patch)
tree25fd5b0f90f4b5a651d6b053dcdf01f6b17da43e
parente6a71fd6770c36560cb9d8451ae36cc3c0018ba3 (diff)
downloadnavit-ab945bdc1a75f8d6568b7a00a46698de8427878e.tar.gz
maptool: migrate malloc to g_malloc
-rw-r--r--navit/maptool/buffer.c3
-rw-r--r--navit/maptool/ch.c2
-rw-r--r--navit/maptool/misc.c3
-rw-r--r--navit/maptool/osm_protobuf.c4
-rw-r--r--navit/maptool/osm_protobufdb.c32
-rw-r--r--navit/maptool/tile.c8
-rw-r--r--navit/maptool/zip.c6
7 files changed, 25 insertions, 33 deletions
diff --git a/navit/maptool/buffer.c b/navit/maptool/buffer.c
index e6f8beea0..bc191419c 100644
--- a/navit/maptool/buffer.c
+++ b/navit/maptool/buffer.c
@@ -74,8 +74,7 @@ load_buffer(char *filename, struct buffer *b, long long offset, long long size)
dbg_assert(b->size>0);
fseeko(f, offset, SEEK_SET);
- b->base=malloc(b->size);
- dbg_assert(b->base != NULL);
+ b->base=g_malloc(b->size);
if (fread(b->base, b->size, 1, f) == 0){
dbg(lvl_warning, "fread failed");
return 0;
diff --git a/navit/maptool/ch.c b/navit/maptool/ch.c
index b1f7d9d01..be0f22b48 100644
--- a/navit/maptool/ch.c
+++ b/navit/maptool/ch.c
@@ -529,7 +529,7 @@ ch_assemble_map(char *map_suffix, char *suffix, struct zip_info *zip_info)
}
th=tile_head_root;
while (th) {
- th->zip_data=malloc(th->total_size);
+ th->zip_data=g_malloc(th->total_size);
th->total_size_used=0;
th=th->next;
}
diff --git a/navit/maptool/misc.c b/navit/maptool/misc.c
index 90b03d462..53ed24407 100644
--- a/navit/maptool/misc.c
+++ b/navit/maptool/misc.c
@@ -326,8 +326,7 @@ process_slice(FILE **in, FILE **reference, int in_count, int with_range, long lo
struct tile_info info;
int i;
- slice_data=malloc(size);
- assert(slice_data != NULL);
+ slice_data=g_malloc(size);
zip_data=slice_data;
th=tile_head_root;
while (th) {
diff --git a/navit/maptool/osm_protobuf.c b/navit/maptool/osm_protobuf.c
index b6eb5f2ca..1216f868a 100644
--- a/navit/maptool/osm_protobuf.c
+++ b/navit/maptool/osm_protobuf.c
@@ -76,7 +76,7 @@ read_blob(OSMPBF__BlobHeader *header, FILE *f, unsigned char *buffer)
static unsigned char *
uncompress_blob(OSMPBF__Blob *blob)
{
- unsigned char *ret=malloc(blob->raw_size);
+ unsigned char *ret=g_malloc(blob->raw_size);
int zerr;
z_stream strm;
@@ -355,7 +355,7 @@ map_collect_data_osm_protobuf(FILE *in, struct maptool_osm *osm)
OSMPBF__BlobHeader *header;
OSMPBF__Blob *blob;
unsigned char *data;
- unsigned char *buffer=malloc(MAX_BLOB_LENGTH);
+ unsigned char *buffer=g_malloc(MAX_BLOB_LENGTH);
#if 0
printf("<?xml version='1.0' encoding='UTF-8'?>\n");
diff --git a/navit/maptool/osm_protobufdb.c b/navit/maptool/osm_protobufdb.c
index 2b242df9c..09625ce4d 100644
--- a/navit/maptool/osm_protobufdb.c
+++ b/navit/maptool/osm_protobufdb.c
@@ -122,11 +122,11 @@ osm_protobufdb_finish_block(struct osm_protobufdb_context *ctx)
osm_protobufdb_write_blob(&empty_blob, ctx->f);
ctx->current_block++;
}
- blob=malloc(sizeof(*blob));
+ blob=g_malloc(sizeof(*blob));
*blob=empty_blob;
blob->has_raw=1;
blob->has_raw_size=1;
- blob->raw.data=malloc(len);
+ blob->raw.data=g_malloc(len);
osmpbf__primitive_block__pack(ctx->pb, blob->raw.data);
blob->raw.len=len;
blob->raw_size=len;
@@ -147,9 +147,9 @@ osm_protobufdb_start_block(struct osm_protobufdb_context *ctx, int blocknum)
return 0;
osm_protobufdb_finish_block(ctx);
ctx->active_block=blocknum;
- ctx->pb=malloc(sizeof(*ctx->pb));
+ ctx->pb=g_malloc(sizeof(*ctx->pb));
*ctx->pb=pb;
- ctx->pb->stringtable=malloc(sizeof(*ctx->pb->stringtable));
+ ctx->pb->stringtable=g_malloc(sizeof(*ctx->pb->stringtable));
*ctx->pb->stringtable=st;
ctx->st=ctx->pb->stringtable;
return 1;
@@ -162,7 +162,7 @@ osm_protobufdb_start_group(struct osm_protobufdb_context *ctx, int groupnum)
if (ctx->pb->n_primitivegroup <= groupnum) {
ctx->pb->primitivegroup=realloc(ctx->pb->primitivegroup, (groupnum+1)*sizeof(ctx->pb->primitivegroup[0]));
while (ctx->pb->n_primitivegroup <= groupnum) {
- ctx->pb->primitivegroup[ctx->pb->n_primitivegroup]=malloc(sizeof(*context.pg));
+ ctx->pb->primitivegroup[ctx->pb->n_primitivegroup]=g_malloc(sizeof(*context.pg));
*ctx->pb->primitivegroup[ctx->pb->n_primitivegroup++]=pg;
}
g_hash_table_destroy(ctx->string_hash);
@@ -170,7 +170,7 @@ osm_protobufdb_start_group(struct osm_protobufdb_context *ctx, int groupnum)
}
ctx->pg=ctx->pb->primitivegroup[groupnum];
if (!ctx->pg) {
- ctx->pg=malloc(sizeof(*context.pg));
+ ctx->pg=g_malloc(sizeof(*context.pg));
*ctx->pg=pg;
ctx->pb->primitivegroup[groupnum]=ctx->pg;
}
@@ -185,13 +185,13 @@ osm_protobufdb_start_densenode(struct osm_protobufdb_context *ctx)
OSMPBF__DenseNodes dn=OSMPBF__DENSE_NODES__INIT;
if (!ctx->pg->dense) {
- ctx->dn=malloc(sizeof(*context.dn));
+ ctx->dn=g_malloc(sizeof(*context.dn));
*ctx->dn=dn;
ctx->pg->dense=ctx->dn;
} else
ctx->dn=ctx->pg->dense;
if (!ctx->dn->denseinfo) {
- ctx->di=malloc(sizeof(*context.di));
+ ctx->di=g_malloc(sizeof(*context.di));
*ctx->di=di;
ctx->dn->denseinfo=ctx->di;
} else
@@ -287,7 +287,7 @@ osm_protobufdb_insert_node(long long id, OSMPBF__PrimitiveGroup *pg)
l=pg->n_nodes;
p=l;
insert(pg, nodes, p);
- pg->nodes[p]=malloc(sizeof(*pg->nodes[0]));
+ pg->nodes[p]=g_malloc(sizeof(*pg->nodes[0]));
*pg->nodes[p]=node;
return p;
}
@@ -312,7 +312,7 @@ osm_protobufdb_modify_node(OSMPBF__Node *node, OSMPBF__Info *info, int pos, OSMP
if (old_info)
n->info=old_info;
else
- n->info=malloc(sizeof(*info));
+ n->info=g_malloc(sizeof(*info));
*n->info=*info;
}
@@ -326,7 +326,7 @@ osm_protobufdb_insert_way(long long id, OSMPBF__PrimitiveGroup *pg)
l=pg->n_ways;
p=l;
insert(pg, ways, p);
- pg->ways[p]=malloc(sizeof(*pg->ways[0]));
+ pg->ways[p]=g_malloc(sizeof(*pg->ways[0]));
*pg->ways[p]=way;
return p;
}
@@ -359,7 +359,7 @@ osm_protobufdb_modify_way(OSMPBF__Way *way, OSMPBF__Info *info, int pos, OSMPBF_
if (old_info)
w->info=old_info;
else
- w->info=malloc(sizeof(*info));
+ w->info=g_malloc(sizeof(*info));
*w->info=*info;
}
@@ -373,7 +373,7 @@ osm_protobufdb_insert_relation(long long id, OSMPBF__PrimitiveGroup *pg)
l=pg->n_relations;
p=l;
insert(pg, relations, p);
- pg->relations[p]=malloc(sizeof(*pg->relations[0]));
+ pg->relations[p]=g_malloc(sizeof(*pg->relations[0]));
*pg->relations[p]=relation;
return p;
}
@@ -410,7 +410,7 @@ osm_protobufdb_modify_relation(OSMPBF__Relation *relation, OSMPBF__Info *info, i
if (old_info)
r->info=old_info;
else
- r->info=malloc(sizeof(*info));
+ r->info=g_malloc(sizeof(*info));
*r->info=*info;
}
@@ -495,9 +495,9 @@ test(void)
context.current_file=-1;
#if 0
- context.di=malloc(sizeof(*context.di));
+ context.di=g_malloc(sizeof(*context.di));
*context.di=di;
- context.dn=malloc(sizeof(*context.dn));
+ context.dn=g_malloc(sizeof(*context.dn));
*context.dn=dn;
#endif
diff --git a/navit/maptool/tile.c b/navit/maptool/tile.c
index d9b1e004a..e9485f2db 100644
--- a/navit/maptool/tile.c
+++ b/navit/maptool/tile.c
@@ -194,8 +194,7 @@ tile_extend(char *tile, struct item_bin *ib, GList **tiles_list)
if (!th)
th=g_hash_table_lookup(tile_hash, tile);
if (! th) {
- th=malloc(sizeof(struct tile_head)+ sizeof( char* ) );
- assert(th != NULL);
+ th=g_malloc(sizeof(struct tile_head)+ sizeof( char* ) );
// strcpy(th->subtiles, tile);
th->num_subtiles=1;
th->total_size=0;
@@ -401,8 +400,7 @@ write_aux_tiles(struct zip_info *zip_info)
while (l) {
at=l->data;
- buffer=malloc(at->size);
- assert(buffer != NULL);
+ buffer=g_malloc(at->size);
f=fopen(at->filename,"rb");
assert(f != NULL);
@@ -496,7 +494,7 @@ load_tilesdir(FILE *in)
tile_hash=g_hash_table_new(g_str_hash, g_str_equal);
last=&tile_head_root;
while (fscanf(in,"%[^:]:%d",tile,&size) == 2) {
- struct tile_head *th=malloc(sizeof(struct tile_head));
+ struct tile_head *th=g_malloc(sizeof(struct tile_head));
if (!strcmp(tile,"index"))
tile[0]='\0';
th->num_subtiles=0;
diff --git a/navit/maptool/zip.c b/navit/maptool/zip.c
index ff9438786..6e62bc14e 100644
--- a/navit/maptool/zip.c
+++ b/navit/maptool/zip.c
@@ -126,11 +126,7 @@ write_zipmember(struct zip_info *zip_info, char *name, int filelen, char *data,
uLongf destlen=data_size+data_size/500+12;
char *compbuffer;
- compbuffer = malloc(destlen);
- if (!compbuffer) {
- fprintf(stderr, "No more memory.\n");
- exit (1);
- }
+ compbuffer = g_malloc(destlen);
crc=crc32(0, NULL, 0);
crc=crc32(crc, (unsigned char *)data, data_size);
lfh.zipmthd=zip_info->compression_level ? 8:0;