annotate LightClone/Source/Util.cpp @ 67:8e7ebab350e7

Clean up memory leaks
author koryspansel
date Fri, 07 Oct 2011 01:15:28 -0700
parents 00d17d8f407d
children
rev   line source
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
1 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
2 * Util
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
3 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
4
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
5 #include "Util.h"
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
6 #include <stdio.h>
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
7
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
8 /*
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
9 * LoadFile
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
10 */
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
11 Buffer LoadFile(const char* pName)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
12 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
13 uint8* pData = NULL;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
14 uint32 nSize = 0;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
15
40
00d17d8f407d Hookup game over dialog; Remove Code class
koryspansel
parents: 0
diff changeset
16 FILE* pFile = fopen(pName, "rt");
00d17d8f407d Hookup game over dialog; Remove Code class
koryspansel
parents: 0
diff changeset
17 if(pFile)
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
18 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
19 fseek(pFile, 0, SEEK_END);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
20 nSize = (uint32)ftell(pFile);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
21 fseek(pFile, 0, SEEK_SET);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
22
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
23 if(nSize > 0)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
24 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
25 pData = new uint8[nSize];
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
26
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
27 uint32 nCount = (uint32)fread(pData, sizeof(uint8), nSize, pFile);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
28 if(nCount != nSize)
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
29 {
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
30 delete[] pData;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
31
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
32 pData = NULL;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
33 nSize = 0;
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
34 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
35 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
36
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
37 fclose(pFile);
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
38 }
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
39
67
8e7ebab350e7 Clean up memory leaks
koryspansel
parents: 40
diff changeset
40 return Buffer(pData, nSize, false);
0
7e3a0ae9c016 Initial commit
koryspansel <koryspansel@bendbroadband.com>
parents:
diff changeset
41 }