Index: libs/mkfat32/main.c |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | memcpy(&((uint8_t*)buf)[0x47], label, 0xb);
|
74 | 74 | memcpy(&((uint8_t*)buf)[0x52], "FAT32 ", 8);
|
75 | 75 | ((uint16_t*)buf)[0xff] = 0xaa55;
|
76 | | - PASS_RC(storage_write_sectors_md(volume, startsector, 1, buf), 2, 0);
|
| 76 | + PASS_RC_FREE(storage_write_sectors_md(volume, startsector, 1, buf), 2, 0, buf);
|
77 | 77 | memset(buf, 0, sectorsize);
|
78 | 78 | buf[0] = 0x41615252;
|
79 | 79 | buf[0x79] = 0x61417272;
|
— | — | @@ -79,7 +79,7 @@ |
80 | 80 | buf[0x7a] = clustercount - 1;
|
81 | 81 | buf[0x7b] = 2;
|
82 | 82 | buf[0x7f] = 0xaa550000;
|
83 | | - PASS_RC(storage_write_sectors_md(volume, startsector + 1, 1, buf), 2, 1);
|
| 83 | + PASS_RC_FREE(storage_write_sectors_md(volume, startsector + 1, 1, buf), 2, 1, buf);
|
84 | 84 | statusinit(statususer, fatsectors);
|
85 | 85 | uint32_t cursect = 0;
|
86 | 86 | for (i = 0; i < fatsectors; i += 32)
|
— | — | @@ -86,14 +86,15 @@ |
87 | 87 | {
|
88 | 88 | memset(buf, 0, 32 * sectorsize);
|
89 | 89 | if (!i) memcpy(buf, "\xf8\xff\xff\x0f\xff\xff\xff\xff\xff\xff\xff\x0f", 12);
|
90 | | - PASS_RC(storage_write_sectors_md(volume, startsector + reserved + i,
|
91 | | - MIN(fatsectors - i, 32), buf), 2, 2);
|
| 90 | + PASS_RC_FREE(storage_write_sectors_md(volume, startsector + reserved + i,
|
| 91 | + MIN(fatsectors - i, 32), buf), 2, 2, buf);
|
92 | 92 | statuscallback(statususer, i);
|
93 | 93 | }
|
94 | 94 | memset(buf, 0, secperclus * sectorsize);
|
95 | 95 | memcpy(buf, label, 11);
|
96 | 96 | ((uint8_t*)buf)[0xc] = 0x80;
|
97 | | - PASS_RC(storage_write_sectors_md(volume, startsector + database, secperclus, buf), 2, 3);
|
| 97 | + PASS_RC_FREE(storage_write_sectors_md(volume, startsector + database,
|
| 98 | + secperclus, buf), 2, 3, buf);
|
98 | 99 | free(buf);
|
99 | 100 | disk_mount(volume);
|
100 | 101 | }
|
Index: emcore/trunk/util.h |
— | — | @@ -60,6 +60,11 @@ |
61 | 61 | mutex_unlock(mutex); \ |
62 | 62 | return ERR_RC(val); \ |
63 | 63 | } |
| 64 | +#define RET_ERR_FREE(val, ptr) \ |
| 65 | +{ \ |
| 66 | + free(ptr); \ |
| 67 | + return ERR_RC(val); \ |
| 68 | +} |
64 | 69 | #define PASS_RC(expr, bits, val) \ |
65 | 70 | { \ |
66 | 71 | int PASS_RC_rc = (expr); \ |
— | — | @@ -75,6 +80,15 @@ |
76 | 81 | return ERR_RC((PASS_RC_MTX_rc << (bits)) | (val)); \ |
77 | 82 | } \ |
78 | 83 | } |
| 84 | +#define PASS_RC_FREE(expr, bits, val, ptr) \ |
| 85 | +{ \ |
| 86 | + int PASS_RC_FREE_rc = (expr); \ |
| 87 | + if (IS_ERR(PASS_RC_FREE_rc)) \ |
| 88 | + { \ |
| 89 | + free(ptr); \ |
| 90 | + return ERR_RC((PASS_RC_FREE_rc << (bits)) | (val)); \ |
| 91 | + } \ |
| 92 | +} |
79 | 93 | |
80 | 94 | #define P2_M1(p2) ((1 << (p2))-1) |
81 | 95 | |