Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32145fea2a | ||
|
|
1691feb9bb | ||
|
|
73a53daf38 | ||
|
|
09c7acf9fc | ||
|
|
d14b612e13 | ||
|
|
45a96fde12 | ||
|
|
9a8d732a13 | ||
|
|
a66aae880c | ||
|
|
3b5a4b7362 | ||
|
|
ce4687fbf9 |
No files matched your search
@@ -1,5 +1,25 @@
|
|||||||
2002-04-18 Robert James Kaes <rjkaes@flarenet.com>
|
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
|
* src/tinyproxy.c (takesig): Moved the filter_destroy() code out
|
||||||
of the signal handler and placed it inside of main(). Same
|
of the signal handler and placed it inside of main(). Same
|
||||||
reasoning as the rotate_log_files() changes below.
|
reasoning as the rotate_log_files() changes below.
|
||||||
|
|||||||
+2
-2
@@ -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 Devlopers, please strive to achieve this order:
|
||||||
dnl
|
dnl
|
||||||
@@ -14,7 +14,7 @@ dnl 8. System services
|
|||||||
dnl
|
dnl
|
||||||
dnl Read the Autoconf manual for details.
|
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_CONFIG_SRCDIR([src/tinyproxy.c])
|
||||||
AC_PREREQ(2.52)
|
AC_PREREQ(2.52)
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
* 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
|
* 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->netmask = 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_acl_ptr->location = strdup(location);
|
new_acl_ptr->location = safestrdup(location);
|
||||||
if (!new_acl_ptr->location) {
|
if (!new_acl_ptr->location) {
|
||||||
safefree(new_acl_ptr);
|
safefree(new_acl_ptr);
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
+3
-3
@@ -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)
|
* Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca)
|
||||||
*
|
*
|
||||||
@@ -67,7 +67,7 @@ filter_init(void)
|
|||||||
if (isspace((unsigned char) *s))
|
if (isspace((unsigned char) *s))
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
|
|
||||||
p->pat = strdup(buf);
|
p->pat = safestrdup(buf);
|
||||||
p->cpat = safemalloc(sizeof(regex_t));
|
p->cpat = safemalloc(sizeof(regex_t));
|
||||||
if ((err =
|
if ((err =
|
||||||
regcomp(p->cpat, p->pat,
|
regcomp(p->cpat, p->pat,
|
||||||
@@ -114,7 +114,7 @@ filter_url(char *host)
|
|||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
/* strip off the port number */
|
/* strip off the port number */
|
||||||
s = strdup(host);
|
s = safestrdup(host);
|
||||||
port = strchr(s, ':');
|
port = strchr(s, ':');
|
||||||
if (port)
|
if (port)
|
||||||
*port = '\0';
|
*port = '\0';
|
||||||
|
|||||||
+21
-36
@@ -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
|
* A hashmap implementation. The keys are case-insensitive NULL terminated
|
||||||
* strings, and the data is arbitrary lumps of data. Copies of both the
|
* 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
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#include "tinyproxy.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 "hashmap.h"
|
#include "hashmap.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These structures are the storage for the hashmap. Entries are stored in
|
* These structures are the storage for the hashmap. Entries are stored in
|
||||||
@@ -112,14 +96,14 @@ hashmap_create(unsigned int nbuckets)
|
|||||||
if (nbuckets == 0)
|
if (nbuckets == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ptr = calloc(1, sizeof(struct hashmap_s));
|
ptr = safecalloc(1, sizeof(struct hashmap_s));
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ptr->size = nbuckets;
|
ptr->size = nbuckets;
|
||||||
ptr->maps = calloc(nbuckets, sizeof(struct hashentry_s *));
|
ptr->maps = safecalloc(nbuckets, sizeof(struct hashentry_s *));
|
||||||
if (!ptr->maps) {
|
if (!ptr->maps) {
|
||||||
free(ptr);
|
safefree(ptr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,9 +130,9 @@ delete_hashentries(struct hashentry_s* entry)
|
|||||||
while (ptr) {
|
while (ptr) {
|
||||||
nextptr = ptr->next;
|
nextptr = ptr->next;
|
||||||
|
|
||||||
free(ptr->key);
|
safefree(ptr->key);
|
||||||
free(ptr->data);
|
safefree(ptr->data);
|
||||||
free(ptr);
|
safefree(ptr);
|
||||||
|
|
||||||
ptr = nextptr;
|
ptr = nextptr;
|
||||||
}
|
}
|
||||||
@@ -175,7 +159,8 @@ hashmap_delete(hashmap_t map)
|
|||||||
delete_hashentries(map->maps[i]);
|
delete_hashentries(map->maps[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(map);
|
safefree(map->maps);
|
||||||
|
safefree(map);
|
||||||
|
|
||||||
return 0;
|
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
|
* First make copies of the key and data in case there is a memory
|
||||||
* problem later.
|
* problem later.
|
||||||
*/
|
*/
|
||||||
key_copy = strdup(key);
|
key_copy = safestrdup(key);
|
||||||
if (!key_copy)
|
if (!key_copy)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
data_copy = malloc(len);
|
data_copy = safemalloc(len);
|
||||||
if (!data_copy) {
|
if (!data_copy) {
|
||||||
free(key_copy);
|
safefree(key_copy);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memcpy(data_copy, data, len);
|
memcpy(data_copy, data, len);
|
||||||
@@ -236,16 +221,16 @@ hashmap_insert(hashmap_t map, const char *key,
|
|||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr = calloc(1, sizeof(struct hashentry_s));
|
ptr = safecalloc(1, sizeof(struct hashentry_s));
|
||||||
ptr->prev = prevptr;
|
ptr->prev = prevptr;
|
||||||
prevptr->next = ptr;
|
prevptr->next = ptr;
|
||||||
} else {
|
} else {
|
||||||
ptr = map->maps[hash] = calloc(1, sizeof(struct hashentry_s));
|
ptr = map->maps[hash] = safecalloc(1, sizeof(struct hashentry_s));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
free(key_copy);
|
safefree(key_copy);
|
||||||
free(data_copy);
|
safefree(data_copy);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,9 +365,9 @@ hashmap_remove(hashmap_t map, const char *key)
|
|||||||
ptr->prev = NULL;
|
ptr->prev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ptr->key);
|
safefree(ptr->key);
|
||||||
free(ptr->data);
|
safefree(ptr->data);
|
||||||
free(ptr);
|
safefree(ptr);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-4
@@ -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
|
* This is where all the work in tinyproxy is actually done. Incoming
|
||||||
* connections have a new thread created for them. The thread then
|
* 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;
|
ssize_t len;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((len = readline(fd, &header)) <= 0)
|
if ((len = readline(fd, &header)) <= 0) {
|
||||||
|
safefree(header);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we received just a CR LF on a line, the headers are
|
* If we received just a CR LF on a line, the headers are
|
||||||
* finished.
|
* finished.
|
||||||
*/
|
*/
|
||||||
if (CHECK_CRLF(header, len))
|
if (CHECK_CRLF(header, len)) {
|
||||||
|
safefree(header);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (add_header_to_connection(hashofheaders, header, len) < 0)
|
if (add_header_to_connection(hashofheaders, header, len) < 0) {
|
||||||
|
safefree(header);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
safefree(header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -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
|
* 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
|
* 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);
|
strlcpy(string, peername->h_name, PEER_STRING_LENGTH);
|
||||||
else
|
else
|
||||||
log_message(LOG_ERR,
|
log_message(LOG_ERR,
|
||||||
"getpeer_string: gethostbyaddr() error \"%s\".",
|
"getpeer_string: gethostbyaddr() error");
|
||||||
hstrerror(h_errno));
|
|
||||||
|
|
||||||
UNLOCK();
|
UNLOCK();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -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,
|
* The initialise routine. Basically sets up all the initial stuff (logfile,
|
||||||
* listening socket, config options, etc.) and then sits there and loops
|
* listening socket, config options, etc.) and then sits there and loops
|
||||||
@@ -173,7 +173,7 @@ main(int argc, char **argv)
|
|||||||
godaemon = FALSE;
|
godaemon = FALSE;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
conf_file = strdup(optarg);
|
conf_file = safestrdup(optarg);
|
||||||
if (!conf_file) {
|
if (!conf_file) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: Could not allocate memory.\n",
|
"%s: Could not allocate memory.\n",
|
||||||
|
|||||||
+39
-5
@@ -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
|
* 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,
|
* 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,
|
debugging_calloc(size_t nmemb, size_t size, const char *file,
|
||||||
unsigned long line)
|
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,
|
fprintf(stderr, "{calloc: %p:%u x %u} %s:%lu\n", ptr, nmemb, size, file,
|
||||||
line);
|
line);
|
||||||
return ptr;
|
return ptr;
|
||||||
@@ -46,7 +51,11 @@ debugging_calloc(size_t nmemb, size_t size, const char *file,
|
|||||||
void *
|
void *
|
||||||
debugging_malloc(size_t size, const char *file, unsigned long line)
|
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);
|
fprintf(stderr, "{malloc: %p:%u} %s:%lu\n", ptr, size, file, line);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
@@ -54,7 +63,12 @@ debugging_malloc(size_t size, const char *file, unsigned long line)
|
|||||||
void *
|
void *
|
||||||
debugging_realloc(void *ptr, size_t size, const char *file, unsigned long line)
|
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,
|
fprintf(stderr, "{realloc: %p -> %p:%u} %s:%lu\n", ptr, newptr, size,
|
||||||
file, line);
|
file, line);
|
||||||
return newptr;
|
return newptr;
|
||||||
@@ -63,11 +77,31 @@ debugging_realloc(void *ptr, size_t size, const char *file, unsigned long line)
|
|||||||
void
|
void
|
||||||
debugging_free(void *ptr, const char *file, unsigned long line)
|
debugging_free(void *ptr, const char *file, unsigned long line)
|
||||||
{
|
{
|
||||||
|
assert(ptr != NULL);
|
||||||
|
|
||||||
fprintf(stderr, "{free: %p} %s:%lu\n", ptr, file, line);
|
fprintf(stderr, "{free: %p} %s:%lu\n", ptr, file, line);
|
||||||
free(ptr);
|
free(ptr);
|
||||||
return;
|
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
|
#endif
|
||||||
|
|
||||||
#define HEADER_SIZE (1024 * 8)
|
#define HEADER_SIZE (1024 * 8)
|
||||||
@@ -164,7 +198,7 @@ send_http_error_message(struct conn_s *connptr)
|
|||||||
int
|
int
|
||||||
indicate_http_error(struct conn_s* connptr, int number, const char* string)
|
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)
|
if (!connptr->error_string)
|
||||||
return -1;
|
return -1;
|
||||||
connptr->error_number = number;
|
connptr->error_number = number;
|
||||||
|
|||||||
+5
-1
@@ -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.
|
* 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_free(void *ptr, const char *file, unsigned long line);
|
||||||
extern void *debugging_realloc(void *ptr, size_t size, const char *file,
|
extern void *debugging_realloc(void *ptr, size_t size, const char *file,
|
||||||
unsigned long line);
|
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 safecalloc(x, y) debugging_calloc(x, y, __FILE__, __LINE__)
|
||||||
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
|
# define safemalloc(x) debugging_malloc(x, __FILE__, __LINE__)
|
||||||
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
|
# define saferealloc(x, y) debugging_realloc(x, y, __FILE__, __LINE__)
|
||||||
# define safefree(x) debugging_free(x, __FILE__, __LINE__)
|
# define safefree(x) debugging_free(x, __FILE__, __LINE__)
|
||||||
|
# define safestrdup(x) debugging_strdup(x, __FILE__, __LINE__)
|
||||||
#else
|
#else
|
||||||
# define safecalloc(x, y) calloc(x, y)
|
# define safecalloc(x, y) calloc(x, y)
|
||||||
# define safemalloc(x) malloc(x)
|
# define safemalloc(x) malloc(x)
|
||||||
# define saferealloc(x, y) realloc(x, y)
|
# define saferealloc(x, y) realloc(x, y)
|
||||||
# define safefree(x) free(x)
|
# define safefree(x) free(x)
|
||||||
|
# define safestrdup(x) strdup(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+10
-17
@@ -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
|
* 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
|
* 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
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(HAVE_CONFIG_H)
|
#include "tinyproxy.h"
|
||||||
# include <config.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These structures are the storage for the "vector". Entries are
|
* These structures are the storage for the "vector". Entries are
|
||||||
@@ -64,7 +57,7 @@ vector_create(void)
|
|||||||
{
|
{
|
||||||
vector_t vector;
|
vector_t vector;
|
||||||
|
|
||||||
vector = malloc(sizeof(struct vector_s));
|
vector = safemalloc(sizeof(struct vector_s));
|
||||||
if (!vector)
|
if (!vector)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -91,13 +84,13 @@ vector_delete(vector_t vector)
|
|||||||
ptr = vector->vector;
|
ptr = vector->vector;
|
||||||
while (ptr) {
|
while (ptr) {
|
||||||
next = ptr->next;
|
next = ptr->next;
|
||||||
free(ptr->data);
|
safefree(ptr->data);
|
||||||
free(ptr);
|
safefree(ptr);
|
||||||
|
|
||||||
ptr = next;
|
ptr = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(vector);
|
safefree(vector);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -119,13 +112,13 @@ vector_insert(vector_t vector, void *data, ssize_t len)
|
|||||||
if (!vector || !data || len <= 0)
|
if (!vector || !data || len <= 0)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
entry = malloc(sizeof(struct vectorentry_s));
|
entry = safemalloc(sizeof(struct vectorentry_s));
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
entry->data = malloc(len);
|
entry->data = safemalloc(len);
|
||||||
if (!entry->data) {
|
if (!entry->data) {
|
||||||
free(entry);
|
safefree(entry);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user