Provide dealloc function to sansapatcher.

Similar as done with ipodpatcher provide a function to free the allocated
sector buffer.

Change-Id: Ie51e82f7191496bb48973148af1cc35cd37993d3
This commit is contained in:
Dominik Riebeling 2013-01-01 13:23:47 +01:00
parent a8d291bd20
commit 163ab46170
6 changed files with 27 additions and 4 deletions

View file

@ -185,8 +185,7 @@ bool Autodetection::detect()
else { else {
qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n; qDebug() << "[Autodetect] sansapatcher: no Sansa found." << n;
} }
free(sansa.sectorbuf); sansa_dealloc_buffer(&sansa);
sansa.sectorbuf = NULL;
if(m_mountpoint.isEmpty() && m_device.isEmpty() if(m_mountpoint.isEmpty() && m_device.isEmpty()
&& m_errdev.isEmpty() && m_incompat.isEmpty()) && m_errdev.isEmpty() && m_incompat.isEmpty())

View file

@ -36,8 +36,7 @@ BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent)
BootloaderInstallSansa::~BootloaderInstallSansa() BootloaderInstallSansa::~BootloaderInstallSansa()
{ {
if(sansa.sectorbuf) { if(sansa.sectorbuf) {
free(sansa.sectorbuf); sansa_dealloc_buffer(&sansa);
sansa.sectorbuf = NULL;
} }
} }

View file

@ -404,6 +404,7 @@ int main(int argc, char* argv[])
} }
sansa_close(&sansa); sansa_close(&sansa);
sansa_dealloc_buffer(&sansa);
if (action==INTERACTIVE) { if (action==INTERACTIVE) {
printf("Press ENTER to exit sansapatcher :"); printf("Press ENTER to exit sansapatcher :");

View file

@ -122,6 +122,16 @@ int sansa_alloc_buffer(struct sansa_t *sansa, int bufsize)
return 0; 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) int sansa_seek(struct sansa_t* sansa, loff_t pos)
{ {
off_t res; off_t res;

View file

@ -162,6 +162,19 @@ int sansa_alloc_buffer(struct sansa_t* sansa, int bufsize)
return 0; 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) int sansa_seek(struct sansa_t* sansa, loff_t pos)
{ {
LARGE_INTEGER li; LARGE_INTEGER li;

View file

@ -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_read(struct sansa_t* sansa, unsigned char* buf, int nbytes);
int sansa_write(struct sansa_t* sansa, int nbytes); int sansa_write(struct sansa_t* sansa, int nbytes);
int sansa_alloc_buffer(struct sansa_t* sansa, int bufsize); int sansa_alloc_buffer(struct sansa_t* sansa, int bufsize);
int sansa_dealloc_buffer(struct sansa_t* sansa);
#ifdef __cplusplus #ifdef __cplusplus
} }