[gs-commits] rev 11141 - in trunk/gs: base psi

robin at ghostscript.com robin at ghostscript.com
Wed Apr 28 11:40:24 UTC 2010


Author: robin
Date: 2010-04-28 11:40:24 +0000 (Wed, 28 Apr 2010)
New Revision: 11141

Modified:
   trunk/gs/base/gsmalloc.c
   trunk/gs/psi/gs.c
   trunk/gs/psi/iapi.c
   trunk/gs/psi/imain.c
Log:
Small tweaks to Ghostscript initialisation to check for malloc failures etc.
This would very rarely have been a problem in current code, but would be
more of an issue in multithreaded operation as running out of memory
while forking a new instance is more likely.

No expected differences, but the local cluster code seems to be claiming
differences for an unchanged tree at the moment, so if 3 or so non-pdfwrite
errors and 1800ish pdfwrite errors show up, it's not because of this.



Modified: trunk/gs/base/gsmalloc.c
===================================================================
--- trunk/gs/base/gsmalloc.c	2010-04-27 16:43:52 UTC (rev 11140)
+++ trunk/gs/base/gsmalloc.c	2010-04-28 11:40:24 UTC (rev 11141)
@@ -109,6 +109,9 @@
     gs_malloc_memory_t *mem =
 	(gs_malloc_memory_t *)malloc(sizeof(gs_malloc_memory_t));
 
+    if (mem == NULL)
+        return NULL;
+
     mem->stable_memory = 0;	/* just for tidyness, never referenced */
     mem->procs = gs_malloc_memory_procs;
     mem->allocated = 0;
@@ -530,6 +533,9 @@
     gs_malloc_memory_t *malloc_memory_default = gs_malloc_memory_init();
     gs_memory_t *memory_t_default;
 
+    if (malloc_memory_default == NULL)
+        return NULL;
+
     if (parent)
 	malloc_memory_default->gs_lib_ctx = parent->gs_lib_ctx;
     else 

Modified: trunk/gs/psi/gs.c
===================================================================
--- trunk/gs/psi/gs.c	2010-04-27 16:43:52 UTC (rev 11140)
+++ trunk/gs/psi/gs.c	2010-04-28 11:40:24 UTC (rev 11141)
@@ -74,6 +74,8 @@
     exit_status = 0;
     mem = gs_malloc_init(NULL);
     minst = gs_main_alloc_instance(mem);
+    code = (minst == NULL ? e_Fatal : 0);
+    if (code >= 0)
     code = gs_main_init_with_args(minst, argc, argv);
     
 #ifdef RUN_STRINGS

Modified: trunk/gs/psi/iapi.c
===================================================================
--- trunk/gs/psi/iapi.c	2010-04-27 16:43:52 UTC (rev 11140)
+++ trunk/gs/psi/iapi.c	2010-04-28 11:40:24 UTC (rev 11141)
@@ -78,7 +78,13 @@
 	mem = gs_malloc_init(NULL);
 	
     }
+    if (mem == NULL)
+        return e_Fatal;
     minst = gs_main_alloc_instance(mem);
+    if (minst == NULL) {
+        gs_malloc_release(mem);
+        return e_Fatal;
+    }
     mem->gs_lib_ctx->top_of_system = (void*) minst;
     mem->gs_lib_ctx->caller_handle = caller_handle;
     mem->gs_lib_ctx->custom_color_callback = NULL;

Modified: trunk/gs/psi/imain.c
===================================================================
--- trunk/gs/psi/imain.c	2010-04-27 16:43:52 UTC (rev 11140)
+++ trunk/gs/psi/imain.c	2010-04-28 11:40:24 UTC (rev 11141)
@@ -70,11 +70,15 @@
 gs_main_instance *
 gs_main_alloc_instance(gs_memory_t *mem)
 {
-    gs_main_instance *minst = 0;
-    if (mem) {
+    gs_main_instance *minst;
+    if (mem == NULL)
+        return NULL;
+
 	minst = (gs_main_instance *) gs_alloc_bytes_immovable(mem, 
 							      sizeof(gs_main_instance),
 							      "init_main_instance");
+    if (minst == NULL)
+        return NULL;
 	memcpy(minst, &gs_main_instance_init_values, sizeof(gs_main_instance_init_values));
 	minst->heap = mem;
 	
@@ -82,7 +86,7 @@
 	mem->gs_lib_ctx->top_of_system = minst;
         /* else top of system is pl_universe */
 #       endif
-    }
+
     return minst;
 }
 



More information about the gs-commits mailing list