Compare commits

...
10 Commits
Author SHA1 Message Date
cvs2svn 32145fea2a This commit was manufactured by cvs2svn to create tag 'rel_1_5_0rc4'. 2002-04-18 18:48:58 +00:00
Robert James Kaes 1691feb9bb Bumped the version number to 1.5.0rc4 2002-04-18 18:48:57 +00:00
Robert James Kaes 73a53daf38 Removed the call to hstrerror() in the getpeer_string() function. It's
not available on all machines.
2002-04-18 18:48:22 +00:00
Robert James Kaes 09c7acf9fc Memory leak in the hashmap_delete() function has been fixed. 2002-04-18 18:41:27 +00:00
Robert James Kaes d14b612e13 Fixed a memory leak in the hashmap_delete function. The array of maps was
not being deleted.
2002-04-18 18:40:38 +00:00
Robert James Kaes 45a96fde12 Changed to vector.c and hashmap.c
Added the debugging_strdup() function.
Fixed a memory leak in get_all_headers.
2002-04-18 18:00:35 +00:00
Robert James Kaes 9a8d732a13 Changed all calls to strdup to safestrdup. This should provide better
memory usage tracking.
2002-04-18 17:59:21 +00:00
Robert James Kaes a66aae880c Fixed a memory leak in reading in headers from the client or server. 2002-04-18 17:58:52 +00:00
Robert James Kaes 3b5a4b7362 Replaced the explicit header includes with one call to tinyproxy.h. Also,
added the utils.h header and changed all the malloc, calloc, free, and
strdup to the appropriate safe variety.
2002-04-18 17:57:20 +00:00
Robert James Kaes ce4687fbf9 Added the debuggin_strdup() function and the associated safestrdup()
macro.  Also, added asserts to the other debugging_* functions.
2002-04-18 17:49:14 +00:00
11 changed files with 118 additions and 75 deletions

No files matched your search

+20
View File
@@ -1,5 +1,25 @@
2002-04-18 Robert James Kaes <rjkaes@flarenet.com>
* src/sock.c (getpeer_string): Removed the hstrerror() call since
it's not supported on all machines, and it's not really needed
anyway.
* src/vector.c:
* src/hashmap.c: Changed all calls to malloc, calloc, free, and
strdup to the appropriate safe variety.
(hashmap_delete): Fixed a memory leak where the maps were not
being freed properly.
* src/utils.c (debugging_strdup): Added this function to be used
by the safestrdup() macro to replace all the calls to strdup().
This should allow better tracking of the memory usage.
Also, all the debugging_* functions have had asserts added to them
to hopefully improve the quality of the code.
* src/reqs.c (get_all_headers): Fixed a memory leak since I was
not freeing the header variable, even though the hashmap makes a
copy of it. Thanks to Petr Lampa for finding this one.
* src/tinyproxy.c (takesig): Moved the filter_destroy() code out
of the signal handler and placed it inside of main(). Same
reasoning as the rotate_log_files() changes below.
+2 -2
View File
@@ -1,4 +1,4 @@
dnl $Id: configure.ac,v 2.19 2002-04-18 17:04:38 rjkaes Exp $
dnl $Id: configure.ac,v 2.20 2002-04-18 18:48:57 rjkaes Exp $
dnl Devlopers, please strive to achieve this order:
dnl
@@ -14,7 +14,7 @@ dnl 8. System services
dnl
dnl Read the Autoconf manual for details.
AC_INIT([tinyproxy], [1.5.0rc3], [rjkaes@users.sourceforge.net])
AC_INIT([tinyproxy], [1.5.0rc4], [rjkaes@users.sourceforge.net])
AC_CONFIG_SRCDIR([src/tinyproxy.c])
AC_PREREQ(2.52)
+2 -2
View File
@@ -1,4 +1,4 @@
/* $Id: acl.c,v 1.13 2002-04-17 20:52:45 rjkaes Exp $
/* $Id: acl.c,v 1.14 2002-04-18 17:59:21 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
@@ -120,7 +120,7 @@ insert_acl(char *location, acl_access_t access_type)
new_acl_ptr->netmask = 32;
}
new_acl_ptr->location = strdup(location);
new_acl_ptr->location = safestrdup(location);
if (!new_acl_ptr->location) {
safefree(new_acl_ptr);
return -1;
+3 -3
View File
@@ -1,4 +1,4 @@
/* $Id: filter.c,v 1.8 2001-11-22 00:31:10 rjkaes Exp $
/* $Id: filter.c,v 1.9 2002-04-18 17:59:21 rjkaes Exp $
*
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
*
@@ -67,7 +67,7 @@ filter_init(void)
if (isspace((unsigned char) *s))
*s = '\0';
p->pat = strdup(buf);
p->pat = safestrdup(buf);
p->cpat = safemalloc(sizeof(regex_t));
if ((err =
regcomp(p->cpat, p->pat,
@@ -114,7 +114,7 @@ filter_url(char *host)
return (0);
/* strip off the port number */
s = strdup(host);
s = safestrdup(host);
port = strchr(s, ':');
if (port)
*port = '\0';
+21 -36
View File
@@ -1,4 +1,4 @@
/* $Id: hashmap.c,v 1.3 2002-04-09 20:05:15 rjkaes Exp $
/* $Id: hashmap.c,v 1.5 2002-04-18 18:40:38 rjkaes Exp $
*
* A hashmap implementation. The keys are case-insensitive NULL terminated
* strings, and the data is arbitrary lumps of data. Copies of both the
@@ -25,27 +25,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#if defined(HAVE_STDINT_H)
# include <stdint.h>
#endif
#if defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#endif
#if defined(HAVE_CTYPE_H)
# include <ctype.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "tinyproxy.h"
#include "hashmap.h"
#include "vector.h"
#include "utils.h"
/*
* These structures are the storage for the hashmap. Entries are stored in
@@ -112,14 +96,14 @@ hashmap_create(unsigned int nbuckets)
if (nbuckets == 0)
return NULL;
ptr = calloc(1, sizeof(struct hashmap_s));
ptr = safecalloc(1, sizeof(struct hashmap_s));
if (!ptr)
return NULL;
ptr->size = nbuckets;
ptr->maps = calloc(nbuckets, sizeof(struct hashentry_s *));
ptr->maps = safecalloc(nbuckets, sizeof(struct hashentry_s *));
if (!ptr->maps) {
free(ptr);
safefree(ptr);
return NULL;
}
@@ -146,9 +130,9 @@ delete_hashentries(struct hashentry_s* entry)
while (ptr) {
nextptr = ptr->next;
free(ptr->key);
free(ptr->data);
free(ptr);
safefree(ptr->key);
safefree(ptr->data);
safefree(ptr);
ptr = nextptr;
}
@@ -175,7 +159,8 @@ hashmap_delete(hashmap_t map)
delete_hashentries(map->maps[i]);
}
free(map);
safefree(map->maps);
safefree(map);
return 0;
}
@@ -214,14 +199,14 @@ hashmap_insert(hashmap_t map, const char *key,
* First make copies of the key and data in case there is a memory
* problem later.
*/
key_copy = strdup(key);
key_copy = safestrdup(key);
if (!key_copy)
return -ENOMEM;
if (data) {
data_copy = malloc(len);
data_copy = safemalloc(len);
if (!data_copy) {
free(key_copy);
safefree(key_copy);
return -ENOMEM;
}
memcpy(data_copy, data, len);
@@ -236,16 +221,16 @@ hashmap_insert(hashmap_t map, const char *key,
ptr = ptr->next;
}
ptr = calloc(1, sizeof(struct hashentry_s));
ptr = safecalloc(1, sizeof(struct hashentry_s));
ptr->prev = prevptr;
prevptr->next = ptr;
} else {
ptr = map->maps[hash] = calloc(1, sizeof(struct hashentry_s));
ptr = map->maps[hash] = safecalloc(1, sizeof(struct hashentry_s));
}
if (!ptr) {
free(key_copy);
free(data_copy);
safefree(key_copy);
safefree(data_copy);
return -ENOMEM;
}
@@ -380,9 +365,9 @@ hashmap_remove(hashmap_t map, const char *key)
ptr->prev = NULL;
}
free(ptr->key);
free(ptr->data);
free(ptr);
safefree(ptr->key);
safefree(ptr->data);
safefree(ptr);
return 1;
}
+12 -4
View File
@@ -1,4 +1,4 @@
/* $Id: reqs.c,v 1.61 2002-04-17 20:55:21 rjkaes Exp $
/* $Id: reqs.c,v 1.62 2002-04-18 17:58:52 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
@@ -546,18 +546,26 @@ get_all_headers(int fd, hashmap_t hashofheaders)
ssize_t len;
for (;;) {
if ((len = readline(fd, &header)) <= 0)
if ((len = readline(fd, &header)) <= 0) {
safefree(header);
return -1;
}
/*
* If we received just a CR LF on a line, the headers are
* finished.
*/
if (CHECK_CRLF(header, len))
if (CHECK_CRLF(header, len)) {
safefree(header);
return 0;
}
if (add_header_to_connection(hashofheaders, header, len) < 0)
if (add_header_to_connection(hashofheaders, header, len) < 0) {
safefree(header);
return -1;
}
safefree(header);
}
}
+2 -3
View File
@@ -1,4 +1,4 @@
/* $Id: sock.c,v 1.28 2002-04-17 20:56:13 rjkaes Exp $
/* $Id: sock.c,v 1.29 2002-04-18 18:48:22 rjkaes Exp $
*
* Sockets are created and destroyed here. When a new connection comes in from
* a client, we need to copy the socket and the create a second socket to the
@@ -275,8 +275,7 @@ getpeer_string(int fd, char *string)
strlcpy(string, peername->h_name, PEER_STRING_LENGTH);
else
log_message(LOG_ERR,
"getpeer_string: gethostbyaddr() error \"%s\".",
hstrerror(h_errno));
"getpeer_string: gethostbyaddr() error");
UNLOCK();
}
+2 -2
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.c,v 1.26 2002-04-18 17:04:04 rjkaes Exp $
/* $Id: tinyproxy.c,v 1.27 2002-04-18 17:59:21 rjkaes Exp $
*
* The initialise routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops
@@ -173,7 +173,7 @@ main(int argc, char **argv)
godaemon = FALSE;
break;
case 'c':
conf_file = strdup(optarg);
conf_file = safestrdup(optarg);
if (!conf_file) {
fprintf(stderr,
"%s: Could not allocate memory.\n",
+39 -5
View File
@@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.26 2002-04-18 16:57:06 rjkaes Exp $
/* $Id: utils.c,v 1.28 2002-04-18 17:59:21 rjkaes Exp $
*
* Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also,
@@ -37,7 +37,12 @@ void *
debugging_calloc(size_t nmemb, size_t size, const char *file,
unsigned long line)
{
void *ptr = calloc(nmemb, size);
void *ptr;
assert(nmemb > 0);
assert(size > 0);
ptr = calloc(nmemb, size);
fprintf(stderr, "{calloc: %p:%u x %u} %s:%lu\n", ptr, nmemb, size, file,
line);
return ptr;
@@ -46,7 +51,11 @@ debugging_calloc(size_t nmemb, size_t size, const char *file,
void *
debugging_malloc(size_t size, const char *file, unsigned long line)
{
void *ptr = malloc(size);
void *ptr;
assert(size > 0);
ptr = malloc(size);
fprintf(stderr, "{malloc: %p:%u} %s:%lu\n", ptr, size, file, line);
return ptr;
}
@@ -54,7 +63,12 @@ debugging_malloc(size_t size, const char *file, unsigned long line)
void *
debugging_realloc(void *ptr, size_t size, const char *file, unsigned long line)
{
void *newptr = realloc(ptr, size);
void *newptr;
assert(ptr != NULL);
assert(size > 0);
newptr = realloc(ptr, size);
fprintf(stderr, "{realloc: %p -> %p:%u} %s:%lu\n", ptr, newptr, size,
file, line);
return newptr;
@@ -63,11 +77,31 @@ debugging_realloc(void *ptr, size_t size, const char *file, unsigned long line)
void
debugging_free(void *ptr, const char *file, unsigned long line)
{
assert(ptr != NULL);
fprintf(stderr, "{free: %p} %s:%lu\n", ptr, file, line);
free(ptr);
return;
}
char*
debugging_strdup(const char* s, const char* file, unsigned long line)
{
char* ptr;
size_t len;
assert(s != NULL);
len = strlen(s) + 1;
ptr = malloc(len);
if (!ptr)
return NULL;
memcpy(ptr, s, len);
fprintf(stderr, "{strdup: %p:%u} %s:%lu\n", ptr, len, file, line);
return ptr;
}
#endif
#define HEADER_SIZE (1024 * 8)
@@ -164,7 +198,7 @@ send_http_error_message(struct conn_s *connptr)
int
indicate_http_error(struct conn_s* connptr, int number, const char* string)
{
connptr->error_string = strdup(string);
connptr->error_string = safestrdup(string);
if (!connptr->error_string)
return -1;
connptr->error_number = number;
+5 -1
View File
@@ -1,4 +1,4 @@
/* $Id: utils.h,v 1.15 2002-04-18 16:57:06 rjkaes Exp $
/* $Id: utils.h,v 1.16 2002-04-18 17:49:14 rjkaes Exp $
*
* See 'utils.h' for a detailed description.
*
@@ -63,16 +63,20 @@ extern void *debugging_malloc(size_t size, const char *file,
extern void debugging_free(void *ptr, const char *file, unsigned long line);
extern void *debugging_realloc(void *ptr, size_t size, const char *file,
unsigned long line);
extern char *debugging_strdup(const char* s, const char* file,
unsigned long line);
# define safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
# define safefree(x) debugging_free(x, __FILE__, __LINE__)
# define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
#else
# define safecalloc(x, y) calloc(x, y)
# define safemalloc(x) malloc(x)
# define saferealloc(x, y) realloc(x, y)
# define safefree(x) free(x)
# define safestrdup(x) strdup(x)
#endif
#endif
+10 -17
View File
@@ -1,4 +1,4 @@
/* $Id: vector.c,v 1.2 2002-04-09 16:28:13 rjkaes Exp $
/* $Id: vector.c,v 1.3 2002-04-18 17:57:19 rjkaes Exp $
*
* A vector implementation. The vector can be of an arbritrary length, and
* the data for each entry is an lump of data (the size is stored in the
@@ -21,17 +21,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#if defined(HAVE_CONFIG_H)
# include <config.h>
#endif
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "tinyproxy.h"
#include "vector.h"
#include "utils.h"
/*
* These structures are the storage for the "vector". Entries are
@@ -64,7 +57,7 @@ vector_create(void)
{
vector_t vector;
vector = malloc(sizeof(struct vector_s));
vector = safemalloc(sizeof(struct vector_s));
if (!vector)
return NULL;
@@ -91,13 +84,13 @@ vector_delete(vector_t vector)
ptr = vector->vector;
while (ptr) {
next = ptr->next;
free(ptr->data);
free(ptr);
safefree(ptr->data);
safefree(ptr);
ptr = next;
}
free(vector);
safefree(vector);
return 0;
}
@@ -119,13 +112,13 @@ vector_insert(vector_t vector, void *data, ssize_t len)
if (!vector || !data || len <= 0)
return -EINVAL;
entry = malloc(sizeof(struct vectorentry_s));
entry = safemalloc(sizeof(struct vectorentry_s));
if (!entry)
return -ENOMEM;
entry->data = malloc(len);
entry->data = safemalloc(len);
if (!entry->data) {
free(entry);
safefree(entry);
return -ENOMEM;
}