aboutsummaryrefslogtreecommitdiff
path: root/src/pj_init.c
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2017-06-01 12:50:23 +0200
committerEven Rouault <even.rouault@spatialys.com>2017-06-01 12:50:23 +0200
commit28cbf0d771a478213c23644650f6c862a9310270 (patch)
tree86667f034b61b59172be1be26f4689469c20b3f7 /src/pj_init.c
parent37369f208496646b88e9728f59a6f7eabc307a96 (diff)
downloadPROJ-28cbf0d771a478213c23644650f6c862a9310270.tar.gz
PROJ-28cbf0d771a478213c23644650f6c862a9310270.zip
Fix memory leaks. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2000. Credit to OSS Fuzz
Diffstat (limited to 'src/pj_init.c')
-rw-r--r--src/pj_init.c53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/pj_init.c b/src/pj_init.c
index e3d99a8f..434ad2ef 100644
--- a/src/pj_init.c
+++ b/src/pj_init.c
@@ -682,26 +682,57 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
else
PIN->from_greenwich = 0.0;
+ /* Private object for the geodesic functions */
+ PIN->geod = pj_calloc (1, sizeof (struct geod_geodesic));
+ if (0!=PIN->geod)
+ geod_init(PIN->geod, PIN->a, (1 - sqrt (1 - PIN->es)));
+
/* projection specific initialization */
- if (!(PIN = (*proj)(PIN)) || ctx->last_errno) {
- bum_call: /* cleanup error return */
+ {
+ /* Backup those variables so that we can clean them in case
+ * (*proj)(PIN) fails */
+ void* gridlist = PIN->gridlist;
+ void* vgridlist_geoid = PIN->vgridlist_geoid;
+ void* catalog_name = PIN->catalog_name;
+ void* geod = PIN->geod;
+ if (!(PIN = (*proj)(PIN)) || ctx->last_errno) {
+ if (PIN)
+ pj_free(PIN);
+ else {
+ for ( ; start; start = curr) {
+ curr = start->next;
+ pj_dalloc(start);
+ }
+ if( gridlist )
+ pj_dalloc( gridlist );
+ if( vgridlist_geoid )
+ pj_dalloc( vgridlist_geoid );
+ if( catalog_name )
+ pj_dalloc( catalog_name );
+ if( geod )
+ pj_dalloc( geod );
+ }
+ PIN = 0;
+ }
+ }
+
+ return PIN;
+
+bum_call: /* cleanup error return */
+ {
if (PIN)
+ {
pj_free(PIN);
- else
+ }
+ else {
for ( ; start; start = curr) {
curr = start->next;
pj_dalloc(start);
}
- PIN = 0;
- }
- else {
- /* Private object for the geodesic functions */
- PIN->geod = pj_calloc (1, sizeof (struct geod_geodesic));
- if (0!=PIN->geod)
- geod_init(PIN->geod, PIN->a, (1 - sqrt (1 - PIN->es)));
+ }
+ return 0;
}
- return PIN;
}
/************************************************************************/