From e49464b38735585eaa0ce01f5734c0bcfad851dd Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sat, 5 Jun 2010 08:58:30 +0000 Subject: [PATCH] Improve error handling. Add some more return checks and fix a memleak on error. Addresses warnings when building with Rockbox Utility. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26569 a1c6a512-1295-4272-9138-f99709370657 --- tools/wavtrim.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/wavtrim.c b/tools/wavtrim.c index 8517b4677e..36a1151b4d 100644 --- a/tools/wavtrim.c +++ b/tools/wavtrim.c @@ -198,12 +198,26 @@ int wavtrim(char * filename, int maxsilence ,char* errstring,int errsize) if (pFile == NULL) { snprintf(errstring,errsize,"Error opening file %s for writing\n",filename); + free(pBuf); return -1; } /* write the new file */ - fwrite(pBuf, 1, datapos, pFile); /* write header */ - fwrite(pBuf + datapos + skip_head, 1, datalen - skip_head - skip_tail, pFile); + if ((int)fwrite(pBuf, 1, datapos, pFile) != datapos) /* write header */ + { + snprintf(errstring,errsize,"Error writing file %s header\n",filename); + fclose(pFile); + free(pBuf); + return -1; + } + if ((int)fwrite(pBuf + datapos + skip_head, 1, datalen - skip_head - skip_tail, pFile) + != datalen - skip_head - skip_tail) + { + snprintf(errstring,errsize,"Error writing file %s data\n",filename); + fclose(pFile); + free(pBuf); + return -1; + } fclose(pFile); free(pBuf);