summaryrefslogtreecommitdiff
path: root/NxWidgets
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-24 20:11:37 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-24 20:11:37 -0600
commita22b02b2fd28f75cdb0e9a7dd72f3be10414d8c0 (patch)
tree109f0cd1c793b85ed0eb5dfd00150fb9f05517bc /NxWidgets
parentff01122e52ae194dd186c30bfa9b0f41cd71539e (diff)
downloadnuttx-a22b02b2fd28f75cdb0e9a7dd72f3be10414d8c0.tar.gz
nuttx-a22b02b2fd28f75cdb0e9a7dd72f3be10414d8c0.tar.bz2
nuttx-a22b02b2fd28f75cdb0e9a7dd72f3be10414d8c0.zip
NxWM:CMediaPlayer: Fix some string handling and memory allocation errors
Diffstat (limited to 'NxWidgets')
-rw-r--r--NxWidgets/nxwm/src/cmediaplayer.cxx15
1 files changed, 8 insertions, 7 deletions
diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx
index 35cba1e30..8f833638c 100644
--- a/NxWidgets/nxwm/src/cmediaplayer.cxx
+++ b/NxWidgets/nxwm/src/cmediaplayer.cxx
@@ -413,7 +413,7 @@ bool CMediaPlayer::getMediaFile(const NXWidgets::CListBoxDataItem *item)
// Get the path to the file as a regular C-style string
NXWidgets::nxwidget_char_t *filePath =
- new NXWidgets::nxwidget_char_t[m_filePath.getAllocSize() + 1];
+ new NXWidgets::nxwidget_char_t[newFilePath.getAllocSize()];
if (!filePath)
{
@@ -421,20 +421,21 @@ bool CMediaPlayer::getMediaFile(const NXWidgets::CListBoxDataItem *item)
return false;
}
- m_filePath.copyToCharArray(filePath);
+ newFilePath.copyToCharArray(filePath);
// Verify that the file of this name exists and that it is a not
// something weird (like a directory or a block device).
+ //
// REVISIT: Should check if read-able as well.
struct stat buf;
int ret = stat((FAR const char *)filePath, &buf);
- delete filePath;
+ delete[] filePath;
if (ret < 0)
{
int errcode = errno;
- dbg("ERROR: Could not stat file: %d\n", errcode);
+ dbg("ERROR: Could not stat file %s: %d\n", filePath, errcode);
// Make sure there is no previous file information
@@ -1587,7 +1588,7 @@ void CMediaPlayer::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
// Get the path to the file as a regular C-style string
NXWidgets::nxwidget_char_t *filePath =
- new NXWidgets::nxwidget_char_t[m_filePath.getAllocSize() + 1];
+ new NXWidgets::nxwidget_char_t[m_filePath.getAllocSize()];
if (!filePath)
{
@@ -1603,14 +1604,14 @@ void CMediaPlayer::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
AUDIO_FMT_UNDEF, AUDIO_FMT_UNDEF);
if (ret < 0)
{
- dbg("ERROR: nxplayer_playfile failed: %d\n", ret);
+ dbg("ERROR: nxplayer_playfile %s failed: %d\n", filePath, ret);
}
else
{
setMediaPlayerState(MPLAYER_PLAYING);
}
- delete filePath;
+ delete[] filePath;
}
}