Changed all the mallocs and callocs to use the new safemalloc and
safecalloc.
This commit is contained in:
parent
d5253ec5f4
commit
0668e42e8f
@ -1,4 +1,4 @@
|
||||
/* $Id: acl.c,v 1.5 2001-09-07 04:16:33 rjkaes Exp $
|
||||
/* $Id: acl.c,v 1.6 2001-09-08 18:58:37 rjkaes Exp $
|
||||
*
|
||||
* This system handles Access Control for use of this daemon. A list of
|
||||
* domains, or IP addresses (including IP blocks) are stored in a list
|
||||
@ -24,6 +24,7 @@
|
||||
#include "acl.h"
|
||||
#include "log.h"
|
||||
#include "sock.h"
|
||||
#include "utils.h"
|
||||
|
||||
struct acl_s {
|
||||
acl_access_t acl_access;
|
||||
@ -93,7 +94,7 @@ int insert_acl(char *location, acl_access_t access_type)
|
||||
rev_acl_ptr = &acl_ptr->next;
|
||||
acl_ptr = acl_ptr->next;
|
||||
}
|
||||
new_acl_ptr = malloc(sizeof(struct acl_s));
|
||||
new_acl_ptr = safemalloc(sizeof(struct acl_s));
|
||||
if (!new_acl_ptr) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: buffer.c,v 1.6 2001-09-07 04:17:03 rjkaes Exp $
|
||||
/* $Id: buffer.c,v 1.7 2001-09-08 18:58:37 rjkaes Exp $
|
||||
*
|
||||
* The buffer used in each connection is a linked list of lines. As the lines
|
||||
* are read in and written out the buffer expands and contracts. Basically,
|
||||
@ -63,7 +63,7 @@ static struct bufline_s *makenewline(unsigned char *data, size_t length)
|
||||
|
||||
assert(data != NULL);
|
||||
|
||||
if (!(newline = malloc(sizeof(struct bufline_s))))
|
||||
if (!(newline = safemalloc(sizeof(struct bufline_s))))
|
||||
return NULL;
|
||||
|
||||
newline->string = data;
|
||||
@ -98,7 +98,7 @@ struct buffer_s *new_buffer(void)
|
||||
{
|
||||
struct buffer_s *buffptr;
|
||||
|
||||
if (!(buffptr = malloc(sizeof(struct buffer_s))))
|
||||
if (!(buffptr = safemalloc(sizeof(struct buffer_s))))
|
||||
return NULL;
|
||||
|
||||
buffptr->head = buffptr->tail = NULL;
|
||||
@ -198,7 +198,7 @@ ssize_t readbuff(int fd, struct buffer_s *buffptr)
|
||||
bytesin = read(fd, inbuf, MAXBUFFSIZE - buffer_size(buffptr));
|
||||
|
||||
if (bytesin > 0) {
|
||||
if (!(buffer = malloc(bytesin))) {
|
||||
if (!(buffer = safemalloc(bytesin))) {
|
||||
log_message(LOG_ERR, "Could not allocate memory in 'readbuff'");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: filter.c,v 1.4 2001-05-27 02:24:40 rjkaes Exp $
|
||||
/* $Id: filter.c,v 1.5 2001-09-08 18:58:37 rjkaes Exp $
|
||||
*
|
||||
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
|
||||
*
|
||||
@ -54,11 +54,11 @@ void filter_init(void)
|
||||
s = buf;
|
||||
if (!p) /* head of list */
|
||||
fl = p = (struct filter_list *)
|
||||
malloc(sizeof
|
||||
safemalloc(sizeof
|
||||
(struct filter_list));
|
||||
else { /* next entry */
|
||||
p->next = (struct filter_list *)
|
||||
malloc(sizeof
|
||||
safemalloc(sizeof
|
||||
(struct filter_list));
|
||||
p = p->next;
|
||||
}
|
||||
@ -71,7 +71,7 @@ void filter_init(void)
|
||||
*s = '\0';
|
||||
|
||||
p->pat = strdup(buf);
|
||||
p->cpat = malloc(sizeof(regex_t));
|
||||
p->cpat = safemalloc(sizeof(regex_t));
|
||||
if ((err = regcomp(p->cpat, p->pat, REG_NEWLINE | REG_NOSUB)) != 0) {
|
||||
fprintf(stderr,
|
||||
"Bad regex in %s: %s\n",
|
||||
|
12
src/reqs.c
12
src/reqs.c
@ -1,4 +1,4 @@
|
||||
/* $Id: reqs.c,v 1.20 2001-09-07 04:18:04 rjkaes Exp $
|
||||
/* $Id: reqs.c,v 1.21 2001-09-08 18:58:37 rjkaes Exp $
|
||||
*
|
||||
* This is where all the work in tinyproxy is actually done. Incoming
|
||||
* connections have a new thread created for them. The thread then
|
||||
@ -171,7 +171,7 @@ static int process_method(struct conn_s *connptr)
|
||||
}
|
||||
|
||||
len = pmatch[URI_IND].rm_eo - pmatch[URI_IND].rm_so;
|
||||
if (!(buffer = malloc(len + 1))) {
|
||||
if (!(buffer = safemalloc(len + 1))) {
|
||||
log_message(LOG_ERR,
|
||||
"Could not allocate memory for request from [%s].",
|
||||
peer_ipaddr);
|
||||
@ -193,7 +193,7 @@ static int process_method(struct conn_s *connptr)
|
||||
char *error_string;
|
||||
if (uri->scheme) {
|
||||
size_t error_string_len = strlen(uri->scheme) + 64;
|
||||
error_string = malloc(error_string_len);
|
||||
error_string = safemalloc(error_string_len);
|
||||
if (!error_string) {
|
||||
log_message(LOG_ERR,
|
||||
"Could not allocate memory for request from [%s].",
|
||||
@ -256,7 +256,7 @@ static int process_method(struct conn_s *connptr)
|
||||
|
||||
/* Build a new request from the first line of the header */
|
||||
request_len = strlen(inbuf) + 1;
|
||||
if (!(request = malloc(request_len))) {
|
||||
if (!(request = safemalloc(request_len))) {
|
||||
log_message(LOG_ERR,
|
||||
"Could not allocate memory for request from [%s].",
|
||||
peer_ipaddr);
|
||||
@ -334,7 +334,7 @@ static int compare_header(char *line)
|
||||
if ((ptr = strstr(line, ":")) == NULL)
|
||||
return -1;
|
||||
|
||||
if ((buffer = malloc(ptr - line + 1)) == NULL)
|
||||
if ((buffer = safemalloc(ptr - line + 1)) == NULL)
|
||||
return -1;
|
||||
|
||||
memcpy(buffer, line, (size_t)(ptr - line));
|
||||
@ -645,7 +645,7 @@ void handle_connection(int fd)
|
||||
getpeer_string(fd, peer_string),
|
||||
getpeer_ip(fd, peer_ipaddr));
|
||||
|
||||
connptr = malloc(sizeof(struct conn_s));
|
||||
connptr = safemalloc(sizeof(struct conn_s));
|
||||
if (!connptr) {
|
||||
log_message(LOG_ERR,
|
||||
"Could not allocate memory for request from [%s]",
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: stats.c,v 1.4 2001-05-27 02:26:53 rjkaes Exp $
|
||||
/* $Id: stats.c,v 1.5 2001-09-08 18:58:37 rjkaes Exp $
|
||||
*
|
||||
* This module handles the statistics for tinyproxy. There are only two
|
||||
* public API functions. The reason for the functions, rather than just a
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "stats.h"
|
||||
#include "utils.h"
|
||||
|
||||
struct stat_s {
|
||||
unsigned long int num_reqs;
|
||||
@ -72,7 +73,7 @@ int showstats(struct conn_s *connptr)
|
||||
"Number of refused connections due to high load: %lu\r\n" \
|
||||
"</blockquote>\r\n</body></html>\r\n";
|
||||
|
||||
connptr->output_message = malloc(MAXBUFFSIZE);
|
||||
connptr->output_message = safemalloc(MAXBUFFSIZE);
|
||||
if (!connptr->output_message) {
|
||||
log_message(LOG_CRIT, "Out of memory!");
|
||||
return -1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: thread.c,v 1.13 2001-09-08 06:29:04 rjkaes Exp $
|
||||
/* $Id: thread.c,v 1.14 2001-09-08 18:58:37 rjkaes Exp $
|
||||
*
|
||||
* Handles the creation/destruction of the various threads required for
|
||||
* processing incoming connections.
|
||||
@ -22,6 +22,7 @@
|
||||
#include "reqs.h"
|
||||
#include "sock.h"
|
||||
#include "thread.h"
|
||||
#include "utils.h"
|
||||
|
||||
/*
|
||||
* This is the stack frame size used by all the threads. We'll start by
|
||||
@ -117,7 +118,7 @@ static void *thread_main(void *arg)
|
||||
|
||||
ptr = (struct thread_s *)arg;
|
||||
|
||||
cliaddr = malloc(addrlen);
|
||||
cliaddr = safemalloc(addrlen);
|
||||
if (!cliaddr) {
|
||||
log_message(LOG_ERR, "Could not allocate memory in 'thread_main'.");
|
||||
return NULL;
|
||||
@ -205,7 +206,7 @@ short int thread_pool_create(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
thread_ptr = calloc((size_t)thread_config.maxclients, sizeof(struct thread_s));
|
||||
thread_ptr = safecalloc((size_t)thread_config.maxclients, sizeof(struct thread_s));
|
||||
if (!thread_ptr)
|
||||
return -1;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: tinyproxy.h,v 1.13 2001-08-29 04:04:01 rjkaes Exp $
|
||||
/* $Id: tinyproxy.h,v 1.14 2001-09-08 18:58:37 rjkaes Exp $
|
||||
*
|
||||
* See 'tinyproxy.c' for a detailed description.
|
||||
*
|
||||
@ -78,8 +78,6 @@
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#define safefree(x) do { free(x); x = NULL; } while (0)
|
||||
|
||||
/* Make a new type: bool_t */
|
||||
typedef enum {
|
||||
FALSE = 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user