summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-05-01 21:35:06 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-05-01 21:35:06 +0000
commitb22516f995ef4a448251b883b0737d4aa0abdb84 (patch)
treee022040257aaf8f7e9fbc4b004acdea7e1d55ca9
parentf4943b90e69e75cc2301238969520914553d7ae5 (diff)
downloadrockbox-b22516f995ef4a448251b883b0737d4aa0abdb84.zip
rockbox-b22516f995ef4a448251b883b0737d4aa0abdb84.tar.gz
rockbox-b22516f995ef4a448251b883b0737d4aa0abdb84.tar.bz2
rockbox-b22516f995ef4a448251b883b0737d4aa0abdb84.tar.xz
Make sure the global buffers for ipodpatcher and sansapatcher get allocated and freed only once. Fixes segfaults when the bootloader install class was instanciated multiple times.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20835 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/ipodpatcher/ipodpatcher.c2
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstallipod.cpp12
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstallsansa.cpp12
-rw-r--r--rbutil/sansapatcher/sansapatcher.c2
4 files changed, 20 insertions, 8 deletions
diff --git a/rbutil/ipodpatcher/ipodpatcher.c b/rbutil/ipodpatcher/ipodpatcher.c
index 73467de..dd65050 100644
--- a/rbutil/ipodpatcher/ipodpatcher.c
+++ b/rbutil/ipodpatcher/ipodpatcher.c
@@ -50,7 +50,7 @@
int ipod_verbose = 0;
-unsigned char* ipod_sectorbuf;
+unsigned char* ipod_sectorbuf = NULL;
/* The following string appears at the start of the firmware partition */
static const char *apple_stop_sign = "{{~~ /-----\\ "\
diff --git a/rbutil/rbutilqt/base/bootloaderinstallipod.cpp b/rbutil/rbutilqt/base/bootloaderinstallipod.cpp
index e4a70e0..f622225 100644
--- a/rbutil/rbutilqt/base/bootloaderinstallipod.cpp
+++ b/rbutil/rbutilqt/base/bootloaderinstallipod.cpp
@@ -30,15 +30,21 @@ BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent)
{
(void)parent;
// initialize sector buffer. ipod_sectorbuf is defined in ipodpatcher.
- ipod_sectorbuf = NULL;
- ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE);
+ // The buffer itself is only present once, so make sure to not allocate
+ // it if it was already allocated. The application needs to take care
+ // no concurrent (i.e. multiple objects of this class running) requests
+ // are done.
+ if(ipod_sectorbuf == NULL)
+ ipod_alloc_buffer(&ipod_sectorbuf, BUFFER_SIZE);
}
BootloaderInstallIpod::~BootloaderInstallIpod()
{
- if(ipod_sectorbuf)
+ if(ipod_sectorbuf) {
free(ipod_sectorbuf);
+ ipod_sectorbuf = NULL;
+ }
}
diff --git a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp
index aab298c..1975044 100644
--- a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp
+++ b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp
@@ -30,15 +30,21 @@ BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent)
(void)parent;
// initialize sector buffer. sansa_sectorbuf is instantiated by
// sansapatcher.
- sansa_sectorbuf = NULL;
- sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
+ // The buffer itself is only present once, so make sure to not allocate
+ // it if it was already allocated. The application needs to take care
+ // no concurrent (i.e. multiple objects of this class running) requests
+ // are done.
+ if(sansa_sectorbuf == NULL)
+ sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
}
BootloaderInstallSansa::~BootloaderInstallSansa()
{
- if(sansa_sectorbuf)
+ if(sansa_sectorbuf) {
free(sansa_sectorbuf);
+ sansa_sectorbuf = NULL;
+ }
}
diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c
index 8d31919..015e5cb 100644
--- a/rbutil/sansapatcher/sansapatcher.c
+++ b/rbutil/sansapatcher/sansapatcher.c
@@ -47,7 +47,7 @@ int sansa_verbose = 0;
and initialise it with sansa_alloc_buf() in main().
*/
-unsigned char* sansa_sectorbuf;
+unsigned char* sansa_sectorbuf = NULL;
static off_t filesize(int fd) {
struct stat buf;