Provide dealloc function to ipodpatcher.
On Windows the sector buffer is allocated using VirtualAlloc, thus releasing this buffer should be done using VirtualFree. Provide an additional function for deallocating the buffer so users of ipodpatcher do not need to know about this. Change-Id: Ibb0fc575a185148a389e63935e86a392bf8d180d
This commit is contained in:
parent
45cda1fdcc
commit
b63d429c8f
6 changed files with 27 additions and 4 deletions
|
@ -367,6 +367,16 @@ int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ipod_dealloc_buffer(struct ipod_t* ipod)
|
||||||
|
{
|
||||||
|
if (ipod->sectorbuf == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(ipod->sectorbuf);
|
||||||
|
ipod->sectorbuf = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ipod_seek(struct ipod_t* ipod, unsigned long pos)
|
int ipod_seek(struct ipod_t* ipod, unsigned long pos)
|
||||||
{
|
{
|
||||||
off_t res;
|
off_t res;
|
||||||
|
|
|
@ -170,6 +170,19 @@ int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ipod_dealloc_buffer(struct ipod_t* ipod)
|
||||||
|
{
|
||||||
|
if (ipod->sectorbuf == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(!VirtualFree(ipod->sectorbuf, 0, MEM_RELEASE)) {
|
||||||
|
ipod_print_error(" Error releasing buffer ");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
ipod->sectorbuf = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ipod_seek(struct ipod_t* ipod, unsigned long pos)
|
int ipod_seek(struct ipod_t* ipod, unsigned long pos)
|
||||||
{
|
{
|
||||||
if (SetFilePointer(ipod->dh, pos, NULL, FILE_BEGIN)==0xffffffff) {
|
if (SetFilePointer(ipod->dh, pos, NULL, FILE_BEGIN)==0xffffffff) {
|
||||||
|
|
|
@ -107,6 +107,7 @@ int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code,
|
||||||
ssize_t ipod_read(struct ipod_t* ipod, int nbytes);
|
ssize_t ipod_read(struct ipod_t* ipod, int nbytes);
|
||||||
ssize_t ipod_write(struct ipod_t* ipod, int nbytes);
|
ssize_t ipod_write(struct ipod_t* ipod, int nbytes);
|
||||||
int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize);
|
int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize);
|
||||||
|
int ipod_dealloc_buffer(struct ipod_t* ipod);
|
||||||
|
|
||||||
/* In fat32format.c */
|
/* In fat32format.c */
|
||||||
int format_partition(struct ipod_t* ipod, int partition);
|
int format_partition(struct ipod_t* ipod, int partition);
|
||||||
|
|
|
@ -614,5 +614,6 @@ int main(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ipod_dealloc_buffer(&ipod);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,8 +162,7 @@ bool Autodetection::detect()
|
||||||
else {
|
else {
|
||||||
qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n;
|
qDebug() << "[Autodetect] ipodpatcher: no Ipod found." << n;
|
||||||
}
|
}
|
||||||
free(ipod.sectorbuf);
|
ipod_dealloc_buffer(&ipod);
|
||||||
ipod.sectorbuf = NULL;
|
|
||||||
|
|
||||||
// try sansapatcher
|
// try sansapatcher
|
||||||
// initialize sector buffer. Needed.
|
// initialize sector buffer. Needed.
|
||||||
|
|
|
@ -37,8 +37,7 @@ BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent)
|
||||||
BootloaderInstallIpod::~BootloaderInstallIpod()
|
BootloaderInstallIpod::~BootloaderInstallIpod()
|
||||||
{
|
{
|
||||||
if(ipod.sectorbuf) {
|
if(ipod.sectorbuf) {
|
||||||
free(ipod.sectorbuf);
|
ipod_dealloc_buffer(&ipod);
|
||||||
ipod.sectorbuf = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue