aboutsummaryrefslogtreecommitdiff
path: root/src/pj_gridinfo.c
diff options
context:
space:
mode:
authorAaron Puchert <aaronpuchert@alice-dsl.net>2017-10-19 14:04:35 +0200
committerThomas Knudsen <busstoptaktik@users.noreply.github.com>2017-10-19 14:04:35 +0200
commit3ef083767eaf975399243246605fddc40cc097f9 (patch)
treeb2c45357d24f2a13850bbc46fea781a583436fc0 /src/pj_gridinfo.c
parentfe3e7fd972682e3fec6926a7cc66ededeab55701 (diff)
downloadPROJ-3ef083767eaf975399243246605fddc40cc097f9.tar.gz
PROJ-3ef083767eaf975399243246605fddc40cc097f9.zip
Prevent crashes and leaks on allocation failure (#606)
* Prevent crashes and leaks on allocation failure Memory allocation can fail. We need to gracefully handle this case and prevent dereferencing null pointers. * Make NULL checks consistent within a file * Properly report allocation errors * Improve cleanup in pj_gc_reader.c * Implement pj_strdup and use instead of strdup The function strdup is not part of ANSI C 89, but a POSIX extension. Therefore we can not rely on it being available on all platforms.
Diffstat (limited to 'src/pj_gridinfo.c')
-rw-r--r--src/pj_gridinfo.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/pj_gridinfo.c b/src/pj_gridinfo.c
index 458f0f2b..332a0ffb 100644
--- a/src/pj_gridinfo.c
+++ b/src/pj_gridinfo.c
@@ -570,8 +570,8 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
gi = (PJ_GRIDINFO *) pj_malloc(sizeof(PJ_GRIDINFO));
memset( gi, 0, sizeof(PJ_GRIDINFO) );
- gi->gridname = strdup( gilist->gridname );
- gi->filename = strdup( gilist->filename );
+ gi->gridname = pj_strdup( gilist->gridname );
+ gi->filename = pj_strdup( gilist->filename );
gi->next = NULL;
}
@@ -866,7 +866,7 @@ PJ_GRIDINFO *pj_gridinfo_init( projCtx ctx, const char *gridname )
gilist = (PJ_GRIDINFO *) pj_malloc(sizeof(PJ_GRIDINFO));
memset( gilist, 0, sizeof(PJ_GRIDINFO) );
- gilist->gridname = strdup( gridname );
+ gilist->gridname = pj_strdup( gridname );
gilist->filename = NULL;
gilist->format = "missing";
gilist->grid_offset = 0;
@@ -882,7 +882,7 @@ PJ_GRIDINFO *pj_gridinfo_init( projCtx ctx, const char *gridname )
return gilist;
}
- gilist->filename = strdup(fname);
+ gilist->filename = pj_strdup(fname);
/* -------------------------------------------------------------------- */
/* Load a header, to determine the file type. */