httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Bley <j...@acpub.duke.edu>
Subject [PATCH] malloc checks
Date Tue, 02 Feb 1999 12:09:11 GMT
Here are about seven missed malloc checks or malloc checks that didn't at
least print a message indicating the problem, all located in src/main. 
Given that ap_palloc seems to be used so much throughout the rest of the
source, I wonder if these mallocs should be converted to ap_pallocs
instead.... if so, the patch can be easily converted as such by me or 
anybody with five minutes to spare.

Patch against 1.3.4 in diff -u form.

-- 
John Bley - jbb6@acpub.duke.edu
Duke '99 - English/Computer Science
  Since English is a mess, it maps well onto the problem space,
  which is also a mess, which we call reality.     - Larry Wall

diff -Burp apache_1.3.4_orig/src/main/buff.c apache_1.3.4/src/main/buff.c
--- apache_1.3.4_orig/src/main/buff.c	Fri Jan  1 14:04:47 1999
+++ apache_1.3.4/src/main/buff.c	Tue Feb  2 06:46:03 1999
@@ -1233,8 +1233,10 @@ API_EXPORT(int) ap_bwrite(BUFF *fb, cons
             if (cbuf != NULL)
                 free(cbuf);
             cbuf = malloc(csize = nbyte+HUGE_STRING_LEN);
-            if (cbuf == NULL)
+            if (cbuf == NULL) {
+                fprintf(stderr, "Ouch!  Out of memory!\n");
                 csize = 0;
+            }
         }
         ebcdic2ascii((cbuf) ? cbuf : (void*)buf, buf, nbyte);
         buf = (cbuf) ? cbuf : buf;
diff -Burp apache_1.3.4_orig/src/main/http_config.c apache_1.3.4/src/main/http_config.c
--- apache_1.3.4_orig/src/main/http_config.c	Fri Jan  1 14:04:48 1999
+++ apache_1.3.4/src/main/http_config.c	Tue Feb  2 06:47:04 1999
@@ -327,6 +327,9 @@ static void build_method_shortcuts(void)
 	}
     }
     method_ptrs = malloc((how_many_ptrs + NMETHODS) * sizeof(handler_func));
+    if (method_ptrs == NULL) {
+	fprintf(stderr, "Ouch!  Out of memory!\n");
+    }
     next_ptr = 0;
     for (i = 0; i < NMETHODS; ++i) {
 	/* XXX: This is an itsy bit presumptuous about the alignment
@@ -693,6 +696,9 @@ void ap_setup_prelinked_modules()
      */
     ap_loaded_modules = (module **)malloc(
         sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
+    if (ap_loaded_modules == NULL) {
+	fprintf(stderr, "Ouch!  Out of memory!\n");
+    }
     for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
         *m2++ = *m++;
     *m2 = NULL;
diff -Burp apache_1.3.4_orig/src/main/http_main.c apache_1.3.4/src/main/http_main.c
--- apache_1.3.4_orig/src/main/http_main.c	Fri Jan  8 03:48:46 1999
+++ apache_1.3.4/src/main/http_main.c	Tue Feb  2 06:53:09 1999
@@ -1544,6 +1544,9 @@ static void reinit_scoreboard(pool *p)
 {
     ap_assert(!ap_scoreboard_image);
     ap_scoreboard_image = (scoreboard *) malloc(SCOREBOARD_SIZE);
+    if (ap_scoreboard_image == NULL) {
+	fprintf(stderr, "Ouch!  Out of memory!\n");
+    }
     memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
 }
 
@@ -4809,6 +4812,9 @@ void add_job(int sock)
     /* TODO: If too many jobs in queue, sleep, check for problems */
     ap_acquire_mutex(allowed_globals.jobmutex);
     new_job = (joblist *) malloc(sizeof(joblist));
+    if (new_jobs == NULL) {
+	fprintf(stderr, "Ouch!  Out of memory!\n");
+    }
     new_job->next = NULL;
     new_job->sock = sock;
     if (allowed_globals.jobtail != NULL)
@@ -6117,6 +6123,9 @@ int main(int argc, char *argv[], char *e
     }
     if (llp_slot == NULL) {
 	envpnew = (char **)malloc(sizeof(char *)*(i + 2));
+	if (envpnew == NULL) {
+	    fprintf(stderr, "Ouch!  Out of memory!\n");
+	}
 	memcpy(envpnew, envp, sizeof(char *)*i);
 	envp = envpnew;
 	llp_slot = &envp[i++];
diff -Burp apache_1.3.4_orig/src/main/util.c apache_1.3.4/src/main/util.c
--- apache_1.3.4_orig/src/main/util.c	Fri Jan  8 15:08:23 1999
+++ apache_1.3.4/src/main/util.c	Tue Feb  2 06:45:49 1999
@@ -1373,8 +1373,10 @@ char *strdup(const char *str)
 {
     char *sdup;
 
-    if (!(sdup = (char *) malloc(strlen(str) + 1)))
+    if (!(sdup = (char *) malloc(strlen(str) + 1))) {
+	fprintf(stderr, "Ouch!  Out of memory!\n");
 	return NULL;
+    }
     sdup = strcpy(sdup, str);
 
     return sdup;

Mime
View raw message