fixed a very, very rare and very, very little memory leak
This commit is contained in:
parent
ca134d5522
commit
6a7e53a7c7
15
lib/escape.c
15
lib/escape.c
@ -41,6 +41,7 @@ char *curl_escape(const char *string, int length)
|
|||||||
{
|
{
|
||||||
int alloc = (length?length:(int)strlen(string))+1;
|
int alloc = (length?length:(int)strlen(string))+1;
|
||||||
char *ns = malloc(alloc);
|
char *ns = malloc(alloc);
|
||||||
|
char *testing_ptr = NULL;
|
||||||
unsigned char in;
|
unsigned char in;
|
||||||
int newlen = alloc;
|
int newlen = alloc;
|
||||||
int index=0;
|
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 */
|
newlen += 2; /* the size grows with two, since this'll become a %XX */
|
||||||
if(newlen > alloc) {
|
if(newlen > alloc) {
|
||||||
alloc *= 2;
|
alloc *= 2;
|
||||||
ns = realloc(ns, alloc);
|
testing_ptr = realloc(ns, alloc);
|
||||||
if(!ns)
|
if(!testing_ptr) {
|
||||||
|
free( ns );
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ns = testing_ptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sprintf(&ns[index], "%%%02X", in);
|
sprintf(&ns[index], "%%%02X", in);
|
||||||
|
|
||||||
@ -81,6 +87,10 @@ char *curl_unescape(const char *string, int length)
|
|||||||
int index=0;
|
int index=0;
|
||||||
unsigned int hex;
|
unsigned int hex;
|
||||||
|
|
||||||
|
if( !ns ) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
while(--alloc > 0) {
|
while(--alloc > 0) {
|
||||||
in = *string;
|
in = *string;
|
||||||
if('%' == in) {
|
if('%' == in) {
|
||||||
@ -97,7 +107,6 @@ char *curl_unescape(const char *string, int length)
|
|||||||
}
|
}
|
||||||
ns[index]=0; /* terminate it */
|
ns[index]=0; /* terminate it */
|
||||||
return ns;
|
return ns;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void curl_free(void *p)
|
void curl_free(void *p)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user