realloc: use Curl_saferealloc to avoid common mistakes

Discussed: https://curl.haxx.se/mail/lib-2016-11/0087.html
This commit is contained in:
Daniel Stenberg 2016-11-07 10:55:25 +01:00
parent cdfda3ee82
commit 0649433da5
10 changed files with 48 additions and 27 deletions

View file

@ -71,7 +71,7 @@
#include "url.h"
#include "speedcheck.h"
#include "getinfo.h"
#include "strdup.h"
#include "strcase.h"
#include "vtls/vtls.h"
#include "connect.h"
@ -2112,9 +2112,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* get room for the filename and extra output */
sshc->readdir_totalLen += 4 + sshc->readdir_len;
new_readdir_line = realloc(sshc->readdir_line, sshc->readdir_totalLen);
new_readdir_line = Curl_saferealloc(sshc->readdir_line,
sshc->readdir_totalLen);
if(!new_readdir_line) {
Curl_safefree(sshc->readdir_line);
sshc->readdir_line = NULL;
Curl_safefree(sshc->readdir_filename);
Curl_safefree(sshc->readdir_longentry);
state(conn, SSH_SFTP_CLOSE);