diff options
author | Martin Szulecki | 2011-04-26 15:14:46 +0200 |
---|---|---|
committer | Martin Szulecki | 2011-04-26 15:14:46 +0200 |
commit | d7cdd78d612d18d6dd208756801f08009e04aabe (patch) | |
tree | 0213aa4b5ad26769396868d035799bf66b2fd8a3 /tools | |
parent | e9b5eba30b3272361d846bc78b3bac6e9a8e2b40 (diff) | |
download | libimobiledevice-d7cdd78d612d18d6dd208756801f08009e04aabe.tar.gz libimobiledevice-d7cdd78d612d18d6dd208756801f08009e04aabe.tar.bz2 |
idevicebackup4: Fix memory leaks when receiving files and save device filename
Diffstat (limited to 'tools')
-rw-r--r-- | tools/idevicebackup4.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tools/idevicebackup4.c b/tools/idevicebackup4.c index d7adfc1..3f06a97 100644 --- a/tools/idevicebackup4.c +++ b/tools/idevicebackup4.c @@ -695,6 +695,7 @@ static int mb2_handle_receive_files(plist_t message, const char *backup_dir) uint32_t r; char buf[32768]; char *fname = NULL; + char *dname = NULL; gchar *bname = NULL; char code = 0; char last_code = 0; @@ -726,17 +727,16 @@ static int mb2_handle_receive_files(plist_t message, const char *backup_dir) printf("ERROR: %s: too long device filename (%d)!\n", __func__, nlen); break; } - fname = (char*)malloc(nlen+1); + if (dname != NULL) + free(dname); + dname = (char*)malloc(nlen+1); r = 0; - mobilebackup2_receive_raw(mobilebackup2, fname, nlen, &r); + mobilebackup2_receive_raw(mobilebackup2, dname, nlen, &r); if (r != nlen) { printf("ERROR: %s: could not read device filename\n", __func__); break; } - fname[r] = 0; - // we don't need this name - //printf("\n%s\n", fname); - free(fname); + dname[r] = 0; nlen = 0; mobilebackup2_receive_raw(mobilebackup2, (char*)&nlen, 4, &r); nlen = GUINT32_FROM_BE(nlen); @@ -754,6 +754,8 @@ static int mb2_handle_receive_files(plist_t message, const char *backup_dir) break; } fname[r] = 0; + if (bname != NULL) + g_free(bname); bname = g_build_path(G_DIR_SEPARATOR_S, backup_dir, fname, NULL); free(fname); nlen = 0; @@ -847,6 +849,14 @@ static int mb2_handle_receive_files(plist_t message, const char *backup_dir) free(fname); remove(bname); } + + /* clean up */ + if (bname != NULL) + g_free(bname); + + if (dname != NULL) + free(dname); + // TODO error handling?! mobilebackup2_send_status_response(mobilebackup2, 0, NULL, plist_new_dict()); return file_count; |