1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Fixed some out of memory handling issues.

This commit is contained in:
Dan Fandrich 2007-04-11 00:25:41 +00:00
parent d46d995766
commit 47f044265e
2 changed files with 21 additions and 19 deletions

View File

@ -3647,7 +3647,6 @@ CURLcode Curl_ftp_disconnect(struct connectdata *conn)
static static
CURLcode ftp_parse_url_path(struct connectdata *conn) CURLcode ftp_parse_url_path(struct connectdata *conn)
{ {
CURLcode retcode = CURLE_OK;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
/* the ftp struct is already inited in ftp_connect() */ /* the ftp struct is already inited in ftp_connect() */
struct FTP *ftp = data->reqdata.proto.ftp; struct FTP *ftp = data->reqdata.proto.ftp;
@ -3720,6 +3719,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
if (isBadFtpString(ftpc->dirs[ftpc->dirdepth])) { if (isBadFtpString(ftpc->dirs[ftpc->dirdepth])) {
free(ftpc->dirs[ftpc->dirdepth]);
freedirs(conn); freedirs(conn);
return CURLE_URL_MALFORMAT; return CURLE_URL_MALFORMAT;
} }
@ -3729,7 +3729,6 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
continue; continue;
} }
if(!retcode) {
cur_pos = slash_pos + 1; /* jump to the rest of the string */ cur_pos = slash_pos + 1; /* jump to the rest of the string */
if(++ftpc->dirdepth >= ftpc->diralloc) { if(++ftpc->dirdepth >= ftpc->diralloc) {
/* enlarge array */ /* enlarge array */
@ -3737,14 +3736,12 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
ftpc->diralloc *= 2; /* double the size each time */ ftpc->diralloc *= 2; /* double the size each time */
bigger = realloc(ftpc->dirs, ftpc->diralloc * sizeof(ftpc->dirs[0])); bigger = realloc(ftpc->dirs, ftpc->diralloc * sizeof(ftpc->dirs[0]));
if(!bigger) { if(!bigger) {
ftpc->dirdepth--;
freedirs(conn); freedirs(conn);
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
ftpc->dirs = (char **)bigger; ftpc->dirs = (char **)bigger;
} }
} }
}
ftp->file = cur_pos; /* the rest is the file name */ ftp->file = cur_pos; /* the rest is the file name */
} }
@ -3790,7 +3787,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
free(path); free(path);
} }
return retcode; return CURLE_OK;
} }
/* call this when the DO phase has completed */ /* call this when the DO phase has completed */

View File

@ -286,6 +286,9 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
file name so we skip the always-present first letter of the path string. */ file name so we skip the always-present first letter of the path string. */
filename = curl_easy_unescape(data, &state->conn->data->reqdata.path[1], 0, filename = curl_easy_unescape(data, &state->conn->data->reqdata.path[1], 0,
NULL); NULL);
if (!filename)
return CURLE_OUT_OF_MEMORY;
snprintf((char *)&state->spacket.data[2], snprintf((char *)&state->spacket.data[2],
TFTP_BLOCKSIZE, TFTP_BLOCKSIZE,
"%s%c%s%c", filename, '\0', mode, '\0'); "%s%c%s%c", filename, '\0', mode, '\0');
@ -673,9 +676,9 @@ CURLcode Curl_tftp(struct connectdata *conn, bool *done)
} }
/* Run the TFTP State Machine */ /* Run the TFTP State Machine */
for(tftp_state_machine(state, TFTP_EVENT_INIT); for(code=tftp_state_machine(state, TFTP_EVENT_INIT);
state->state != TFTP_STATE_FIN; (state->state != TFTP_STATE_FIN) && (code == CURLE_OK);
tftp_state_machine(state, event) ) { code=tftp_state_machine(state, event) ) {
/* Wait until ready to read or timeout occurs */ /* Wait until ready to read or timeout occurs */
rc=Curl_socket_ready(state->sockfd, CURL_SOCKET_BAD, state->retry_time * 1000); rc=Curl_socket_ready(state->sockfd, CURL_SOCKET_BAD, state->retry_time * 1000);
@ -761,6 +764,8 @@ CURLcode Curl_tftp(struct connectdata *conn, bool *done)
} }
} }
if(code)
return code;
/* Tell curl we're done */ /* Tell curl we're done */
code = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL); code = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);