Commit df18db13 authored by Rémi Duraffort's avatar Rémi Duraffort

Cleaning and fix potential memleaks.

parent d7fb424d
...@@ -51,8 +51,6 @@ char *XURL_Join( char *psz_url1, char *psz_url2 ) ...@@ -51,8 +51,6 @@ char *XURL_Join( char *psz_url1, char *psz_url2 )
return XURL_Concat( psz_url1, psz_url2 ); return XURL_Concat( psz_url1, psz_url2 );
else else
return XURL_Concat( psz_url2, psz_url1 ); return XURL_Concat( psz_url2, psz_url1 );
return NULL;
} }
/* TODO: replace XURL_Concat's rel/absolute calculation with the one /* TODO: replace XURL_Concat's rel/absolute calculation with the one
...@@ -223,24 +221,20 @@ char *XURL_GetHostname( char *psz_url ) ...@@ -223,24 +221,20 @@ char *XURL_GetHostname( char *psz_url )
char *XURL_GetSchemeAndHostname( char *psz_url ) char *XURL_GetSchemeAndHostname( char *psz_url )
{ {
char *psz_scheme, *psz_hostname, *psz_scheme_and_hostname; char *psz_scheme = NULL,
*psz_hostname = NULL,
*psz_scheme_and_hostname = NULL;
psz_scheme = XURL_GetScheme( psz_url ); psz_scheme = XURL_GetScheme( psz_url );
if( psz_scheme == NULL ) return NULL;
psz_hostname = XURL_GetHostname( psz_url ); psz_hostname = XURL_GetHostname( psz_url );
if( psz_hostname == NULL ) return NULL; if( psz_hostname && psz_scheme )
{
/* malloc +1 for the terminating '\0' */ if( asprintf( &psz_scheme_and_hostname, "%s://%s", psz_scheme, psz_hostname ) == -1)
psz_scheme_and_hostname = malloc( psz_scheme_and_hostname = NULL;
strlen( psz_scheme ) + strlen( "://" ) + }
strlen( psz_hostname ) + 1);
if( psz_scheme_and_hostname == NULL ) return NULL; free( psz_hostname );
strcpy( psz_scheme_and_hostname, psz_scheme ); free( psz_scheme );
strcat( psz_scheme_and_hostname, "://" );
strcat( psz_scheme_and_hostname, psz_hostname );
if( psz_scheme_and_hostname == NULL ) return NULL;
return psz_scheme_and_hostname; return psz_scheme_and_hostname;
} }
...@@ -280,7 +274,8 @@ char *XURL_GetScheme( char *psz_url ) ...@@ -280,7 +274,8 @@ char *XURL_GetScheme( char *psz_url )
size_t i_scheme_length; size_t i_scheme_length;
char *new_scheme; char *new_scheme;
if( XURL_IsAbsolute( psz_url ) == XURL_FALSE ) return strdup( "file" ); if( XURL_IsAbsolute( psz_url ) == XURL_FALSE )
return strdup( "file" );
/* this strchr will always succeed since we have an absolute URL, and thus /* this strchr will always succeed since we have an absolute URL, and thus
* a scheme */ * a scheme */
...@@ -289,10 +284,10 @@ char *XURL_GetScheme( char *psz_url ) ...@@ -289,10 +284,10 @@ char *XURL_GetScheme( char *psz_url )
i_scheme_length = psz_colon - psz_url; i_scheme_length = psz_colon - psz_url;
new_scheme = malloc( i_scheme_length ); new_scheme = malloc( i_scheme_length );
if( new_scheme == NULL ) return NULL; if( new_scheme == NULL )
return NULL;
strncpy( new_scheme, psz_url, i_scheme_length ); strncpy( new_scheme, psz_url, i_scheme_length );
return new_scheme; return new_scheme;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment