Skip to content

Commit

Permalink
Memory leak in CRC32 interface fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rstemmer committed Feb 10, 2019
1 parent 7ff1802 commit 5d050c8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2.1.2 - Memory leak in crc interface fixed
2.1.1 - Do not append padding bytes at the end of the file
2.1.0 - Partial support for extended header: remove (--rm-exthdr) and add checksum (--add-crc)
2.0.3 - Tag version number changes are more obvious now. Only --force2?0 changes it at the beginning of execution.
Expand Down
10 changes: 8 additions & 2 deletions crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ int CRC32FromFile(FILE *file, long from, long to, unsigned long *crc)
}

// Create Buffer
unsigned char *buffer;
unsigned char *buffer;
size_t buffersize = to-from;

buffer = malloc(buffersize * sizeof(char));
buffer = malloc(buffersize * sizeof(unsigned char));
if(buffer == NULL)
{
fprintf(stderr, "%s, %i: ", __FILE__, __LINE__);
Expand All @@ -32,6 +32,7 @@ int CRC32FromFile(FILE *file, long from, long to, unsigned long *crc)
{
fprintf(stderr, "%s, %i: ", __FILE__, __LINE__);
fprintf(stderr, "Fatal Error! - Setting correct file position failed!\n");
free(buffer);
return -1;
}

Expand All @@ -42,12 +43,17 @@ int CRC32FromFile(FILE *file, long from, long to, unsigned long *crc)
{
fprintf(stderr, "%s, %i: ", __FILE__, __LINE__);
fprintf(stderr, "Fatal Error! - Only %zu of %zu bytes read from file!\n", bytesread, buffersize);
free(buffer);
return -1;
}

// Calculate CRC32
if(crc == NULL)
{
free(buffer);
return 0;
}

*crc = crc32(0x00000000, buffer, buffersize);

// Clean up
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <printhex.h>
#include <stdbool.h>

#define VERSION "2.1.0"
#define VERSION "2.1.2"

int CopyArgument(char **dst, char *src);
int ProcessSetArgument(ID3V2 *id3v2, unsigned int ID, const char *argument, unsigned char encoding);
Expand Down

0 comments on commit 5d050c8

Please sign in to comment.