summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2011-04-26 15:14:46 +0200
committerGravatar Martin Szulecki2011-04-26 15:14:46 +0200
commitd7cdd78d612d18d6dd208756801f08009e04aabe (patch)
tree0213aa4b5ad26769396868d035799bf66b2fd8a3
parente9b5eba30b3272361d846bc78b3bac6e9a8e2b40 (diff)
downloadlibimobiledevice-d7cdd78d612d18d6dd208756801f08009e04aabe.tar.gz
libimobiledevice-d7cdd78d612d18d6dd208756801f08009e04aabe.tar.bz2
idevicebackup4: Fix memory leaks when receiving files and save device filename
-rw-r--r--tools/idevicebackup4.c22
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)
695 uint32_t r; 695 uint32_t r;
696 char buf[32768]; 696 char buf[32768];
697 char *fname = NULL; 697 char *fname = NULL;
698 char *dname = NULL;
698 gchar *bname = NULL; 699 gchar *bname = NULL;
699 char code = 0; 700 char code = 0;
700 char last_code = 0; 701 char last_code = 0;
@@ -726,17 +727,16 @@ static int mb2_handle_receive_files(plist_t message, const char *backup_dir)
726 printf("ERROR: %s: too long device filename (%d)!\n", __func__, nlen); 727 printf("ERROR: %s: too long device filename (%d)!\n", __func__, nlen);
727 break; 728 break;
728 } 729 }
729 fname = (char*)malloc(nlen+1); 730 if (dname != NULL)
731 free(dname);
732 dname = (char*)malloc(nlen+1);
730 r = 0; 733 r = 0;
731 mobilebackup2_receive_raw(mobilebackup2, fname, nlen, &r); 734 mobilebackup2_receive_raw(mobilebackup2, dname, nlen, &r);
732 if (r != nlen) { 735 if (r != nlen) {
733 printf("ERROR: %s: could not read device filename\n", __func__); 736 printf("ERROR: %s: could not read device filename\n", __func__);
734 break; 737 break;
735 } 738 }
736 fname[r] = 0; 739 dname[r] = 0;
737 // we don't need this name
738 //printf("\n%s\n", fname);
739 free(fname);
740 nlen = 0; 740 nlen = 0;
741 mobilebackup2_receive_raw(mobilebackup2, (char*)&nlen, 4, &r); 741 mobilebackup2_receive_raw(mobilebackup2, (char*)&nlen, 4, &r);
742 nlen = GUINT32_FROM_BE(nlen); 742 nlen = GUINT32_FROM_BE(nlen);
@@ -754,6 +754,8 @@ static int mb2_handle_receive_files(plist_t message, const char *backup_dir)
754 break; 754 break;
755 } 755 }
756 fname[r] = 0; 756 fname[r] = 0;
757 if (bname != NULL)
758 g_free(bname);
757 bname = g_build_path(G_DIR_SEPARATOR_S, backup_dir, fname, NULL); 759 bname = g_build_path(G_DIR_SEPARATOR_S, backup_dir, fname, NULL);
758 free(fname); 760 free(fname);
759 nlen = 0; 761 nlen = 0;
@@ -847,6 +849,14 @@ static int mb2_handle_receive_files(plist_t message, const char *backup_dir)
847 free(fname); 849 free(fname);
848 remove(bname); 850 remove(bname);
849 } 851 }
852
853 /* clean up */
854 if (bname != NULL)
855 g_free(bname);
856
857 if (dname != NULL)
858 free(dname);
859
850 // TODO error handling?! 860 // TODO error handling?!
851 mobilebackup2_send_status_response(mobilebackup2, 0, NULL, plist_new_dict()); 861 mobilebackup2_send_status_response(mobilebackup2, 0, NULL, plist_new_dict());
852 return file_count; 862 return file_count;