From 163ab4617096edb6384aa8fc7a764d440aee3fb9 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Tue, 1 Jan 2013 13:23:47 +0100 Subject: Provide dealloc function to sansapatcher. Similar as done with ipodpatcher provide a function to free the allocated sector buffer. Change-Id: Ie51e82f7191496bb48973148af1cc35cd37993d3 --- rbutil/rbutilqt/base/autodetection.cpp | 3 +-- rbutil/rbutilqt/base/bootloaderinstallsansa.cpp | 3 +-- rbutil/sansapatcher/main.c | 1 + rbutil/sansapatcher/sansaio-posix.c | 10 ++++++++++ rbutil/sansapatcher/sansaio-win32.c | 13 +++++++++++++ rbutil/sansapatcher/sansaio.h | 1 + 6 files changed, 27 insertions(+), 4 deletions(-) (limited to 'rbutil') diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp index e57c4542d0..4144cca19d 100644 --- a/rbutil/rbutilqt/base/autodetection.cpp +++ b/rbutil/rbutilqt/base/autodetection.cpp @@ -185,8 +185,7 @@ bool Autodetection::detect() else { qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n; } - free(sansa.sectorbuf); - sansa.sectorbuf = NULL; + sansa_dealloc_buffer(&sansa); if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty() && m_incompat.isEmpty()) diff --git a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp index 061ec2578f..49099ebaf8 100644 --- a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp +++ b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp @@ -36,8 +36,7 @@ BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent) BootloaderInstallSansa::~BootloaderInstallSansa() { if(sansa.sectorbuf) { - free(sansa.sectorbuf); - sansa.sectorbuf = NULL; + sansa_dealloc_buffer(&sansa); } } diff --git a/rbutil/sansapatcher/main.c b/rbutil/sansapatcher/main.c index 743ebfedbd..29c2f915bb 100644 --- a/rbutil/sansapatcher/main.c +++ b/rbutil/sansapatcher/main.c @@ -404,6 +404,7 @@ int main(int argc, char* argv[]) } sansa_close(&sansa); + sansa_dealloc_buffer(&sansa); if (action==INTERACTIVE) { printf("Press ENTER to exit sansapatcher :"); diff --git a/rbutil/sansapatcher/sansaio-posix.c b/rbutil/sansapatcher/sansaio-posix.c index d173fbc300..44c4dcc95c 100644 --- a/rbutil/sansapatcher/sansaio-posix.c +++ b/rbutil/sansapatcher/sansaio-posix.c @@ -122,6 +122,16 @@ int sansa_alloc_buffer(struct sansa_t *sansa, int bufsize) return 0; } +int sansa_dealloc_buffer(struct sansa_t* sansa) +{ + if (sansa->sectorbuf == NULL) { + return -1; + } + free(sansa->sectorbuf); + sansa->sectorbuf = NULL; + return 0; +} + int sansa_seek(struct sansa_t* sansa, loff_t pos) { off_t res; diff --git a/rbutil/sansapatcher/sansaio-win32.c b/rbutil/sansapatcher/sansaio-win32.c index 256712fe20..ee6a8cd93d 100644 --- a/rbutil/sansapatcher/sansaio-win32.c +++ b/rbutil/sansapatcher/sansaio-win32.c @@ -162,6 +162,19 @@ int sansa_alloc_buffer(struct sansa_t* sansa, int bufsize) return 0; } +int sansa_dealloc_buffer(struct sansa_t* sansa) +{ + if (sansa->sectorbuf == NULL) { + return -1; + } + if(!VirtualFree(sansa->sectorbuf, 0, MEM_RELEASE)) { + sansa_print_error(" Error releasing buffer "); + return -1; + } + sansa->sectorbuf = NULL; + return 0; +} + int sansa_seek(struct sansa_t* sansa, loff_t pos) { LARGE_INTEGER li; diff --git a/rbutil/sansapatcher/sansaio.h b/rbutil/sansapatcher/sansaio.h index 9e8ebb93c9..61e2f1d1b2 100644 --- a/rbutil/sansapatcher/sansaio.h +++ b/rbutil/sansapatcher/sansaio.h @@ -80,6 +80,7 @@ int sansa_seek(struct sansa_t* sansa, loff_t pos); int sansa_read(struct sansa_t* sansa, unsigned char* buf, int nbytes); int sansa_write(struct sansa_t* sansa, int nbytes); int sansa_alloc_buffer(struct sansa_t* sansa, int bufsize); +int sansa_dealloc_buffer(struct sansa_t* sansa); #ifdef __cplusplus } -- cgit v1.2.3