aboutsummaryrefslogtreecommitdiff
path: root/lib/escape.c
diff options
context:
space:
mode:
authorJean-Philippe Barette-LaPierre <jpbarrette@gmail.com>2003-01-08 02:27:47 +0000
committerJean-Philippe Barette-LaPierre <jpbarrette@gmail.com>2003-01-08 02:27:47 +0000
commit6a7e53a7c7fa468d25adc5d6bda9b6bf6c1abc8c (patch)
treedd86279414ac08a20cde112c8c3ab4852a152da7 /lib/escape.c
parentca134d5522c765d60bc2ffd59410a66c4ba2cf19 (diff)
fixed a very, very rare and very, very little memory leak
Diffstat (limited to 'lib/escape.c')
-rw-r--r--lib/escape.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/escape.c b/lib/escape.c
index 0ec7ae5c0..b35333ddf 100644
--- a/lib/escape.c
+++ b/lib/escape.c
@@ -41,6 +41,7 @@ char *curl_escape(const char *string, int length)
{
int alloc = (length?length:(int)strlen(string))+1;
char *ns = malloc(alloc);
+ char *testing_ptr = NULL;
unsigned char in;
int newlen = alloc;
int index=0;
@@ -55,9 +56,14 @@ char *curl_escape(const char *string, int length)
newlen += 2; /* the size grows with two, since this'll become a %XX */
if(newlen > alloc) {
alloc *= 2;
- ns = realloc(ns, alloc);
- if(!ns)
+ testing_ptr = realloc(ns, alloc);
+ if(!testing_ptr) {
+ free( ns );
return NULL;
+ }
+ else {
+ ns = testing_ptr;
+ }
}
sprintf(&ns[index], "%%%02X", in);
@@ -80,6 +86,10 @@ char *curl_unescape(const char *string, int length)
unsigned char in;
int index=0;
unsigned int hex;
+
+ if( !ns ) {
+ return NULL;
+ }
while(--alloc > 0) {
in = *string;
@@ -97,7 +107,6 @@ char *curl_unescape(const char *string, int length)
}
ns[index]=0; /* terminate it */
return ns;
-
}
void curl_free(void *p)