From 93ac37f27cd6333ad8eea7e7ea3645f1d5a49dbd Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Mon, 27 Dec 2010 09:44:27 +0000 Subject: [PATCH] *Fixed crash on NTFS (wrong memory free functions were used) *Added proper deinitialize of usb before starting game / exiting app. This is supposed to fix Blackops multiplayer mode (Did not test it. I don't have that game.) *Added Wii message board update (Playlog) (thanks to dkosmari for a starting point). This feature can be enabled/disabled in the global settings. Default is ON. *Removed unused sources. --- libcustomntfs/ntfs.c | 10 ++++---- libcustomntfs/ntfsinternal.c | 44 +++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libcustomntfs/ntfs.c b/libcustomntfs/ntfs.c index c2421c25..c5d77999 100644 --- a/libcustomntfs/ntfs.c +++ b/libcustomntfs/ntfs.c @@ -674,14 +674,14 @@ bool ntfsSetVolumeName (const char *name, const char *volumeName) // It does, resize it to match the length of the new volume name if (ntfs_attr_truncate(na, ulabel_len)) { - ntfs_free(ulabel); + free(ulabel); ntfsUnlock(vd); return false; } // Write the new volume name if (ntfs_attr_pwrite(na, 0, ulabel_len, ulabel) != ulabel_len) { - ntfs_free(ulabel); + free(ulabel); ntfsUnlock(vd); return false; } @@ -690,7 +690,7 @@ bool ntfsSetVolumeName (const char *name, const char *volumeName) // It doesn't, create it now if (ntfs_attr_add(vd->vol->vol_ni, AT_VOLUME_NAME, NULL, 0, (u8*)ulabel, ulabel_len)) { - ntfs_free(ulabel); + free(ulabel); ntfsUnlock(vd); return false; } @@ -706,13 +706,13 @@ bool ntfsSetVolumeName (const char *name, const char *volumeName) // Sync the volume node if (ntfs_inode_sync(vd->vol->vol_ni)) { - ntfs_free(ulabel); + free(ulabel); ntfsUnlock(vd); return false; } // Clean up - ntfs_free(ulabel); + free(ulabel); // Unlock ntfsUnlock(vd); diff --git a/libcustomntfs/ntfsinternal.c b/libcustomntfs/ntfsinternal.c index fed15bce..c4db4936 100644 --- a/libcustomntfs/ntfsinternal.c +++ b/libcustomntfs/ntfsinternal.c @@ -316,7 +316,8 @@ ntfs_inode *ntfsParseEntry (ntfs_vd *vd, const char *path, int reparseLevel) ni = ntfsParseEntry(vd, target, reparseLevel++); // Clean up - ntfs_free(target); + // use free because the value was not allocated with ntfs_alloc + free(target); } } @@ -459,11 +460,12 @@ cleanup: if(dir_ni) ntfsCloseEntry(vd, dir_ni); + // use free because the value was not allocated with ntfs_alloc if(utarget) - ntfs_free(utarget); + free(utarget); if(uname) - ntfs_free(uname); + free(uname); if(dir) ntfs_free(dir); @@ -561,8 +563,9 @@ cleanup: if(ni) ntfsCloseEntry(vd, ni); + // use free because the value was not allocated with ntfs_alloc if(uname) - ntfs_free(uname); + free(uname); if(dir) ntfs_free(dir); @@ -657,8 +660,9 @@ cleanup: if(ni) ntfsCloseEntry(vd, ni); + // use free because the value was not allocated with ntfs_alloc if(uname) - ntfs_free(uname); + free(uname); if(dir) ntfs_free(dir); @@ -806,14 +810,33 @@ int ntfsUnicodeToLocal (const ntfschar *ins, const int ins_len, char **outs, int if (!ins || !ins_len || !outs) return 0; - // Convert the unicode string to our current local - len = ntfs_ucstombs(ins, ins_len, outs, outs_len); - if (len == -1 && errno == EILSEQ) { + char * ucstombs_out = NULL; + // Convert the unicode string to our current local + len = ntfs_ucstombs(ins, ins_len, &ucstombs_out, outs_len); + + if(ucstombs_out) + { + //use proper allocation + *outs = (char *) ntfs_alloc(strlen(ucstombs_out) + 1); + if(!*outs) + { + errno = ENOMEM; + return -1; + } + strcpy(*outs, ucstombs_out); + free(ucstombs_out); + ucstombs_out = NULL; + } + + if (len == -1 && errno == EILSEQ) + { // The string could not be converted to the current local, // do it manually by replacing non-ASCII characters with underscores - if (!*outs || outs_len >= ins_len) { - if (!*outs) { + if (!*outs || outs_len >= ins_len) + { + if (!*outs) + { *outs = (char *) ntfs_alloc(ins_len + 1); if (!*outs) { errno = ENOMEM; @@ -829,7 +852,6 @@ int ntfsUnicodeToLocal (const ntfschar *ins, const int ins_len, char **outs, int *outs[ins_len] = (ntfschar)'\0'; len = ins_len; } - } return len;