Skip to content

Commit 020176f

Browse files
committed
fix memory leak and avoid some heap allocations
It's not necessary to heap allocate these small buffers; using the stack avoids the need to remember to free them as well. Refs: #30 Fixes: #31
1 parent a405cec commit 020176f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/extracts.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ void APar_ShowObjectProfileInfo(uint8_t track_type, TrackInfo *track_info) {
724724
} // end switch
725725
} // end level if
726726
} else if (track_type == S_AMR_TRACK) {
727-
char *amr_modes = (char *)calloc(1, sizeof(char) * 500);
727+
char amr_modes[500] = {};
728728
if (track_info->track_codec == 0x73616D72 ||
729729
track_info->track_codec == 0x73617762) {
730730
if (track_info->amr_modes & 0x0001)
@@ -786,9 +786,6 @@ void APar_ShowObjectProfileInfo(uint8_t track_type, TrackInfo *track_info) {
786786
" AMR VBR Wide-Band. Encoder vendor code: %s\n",
787787
track_info->encoder_name);
788788
}
789-
free(amr_modes);
790-
amr_modes = NULL;
791-
792789
} else if (track_type == EVRC_TRACK) {
793790
fprintf(stdout,
794791
" EVRC (Enhanced Variable Rate Coder). Encoder vendor code: %s\n",
@@ -821,7 +818,6 @@ void APar_ShowObjectProfileInfo(uint8_t track_type, TrackInfo *track_info) {
821818
fprintf(stdout, " channels: [%u]\n", track_info->channels);
822819
}
823820
}
824-
return;
825821
}
826822

827823
///////////////////////////////////////////////////////////////////////////////////////
@@ -1592,7 +1588,7 @@ void APar_Print_TrackDetails(TrackInfo *track_info) {
15921588
}
15931589

15941590
void APar_ExtractDetails(FILE *isofile, uint8_t optional_output) {
1595-
char *uint32_buffer = (char *)malloc(sizeof(char) * 5);
1591+
char uint32_buffer[5];
15961592
Trackage track = {0};
15971593

15981594
AtomicInfo *mvhdAtom = APar_FindAtom("moov.mvhd", false, VERSIONED_ATOM, 0);
@@ -1692,14 +1688,13 @@ void APar_ExtractDetails(FILE *isofile, uint8_t optional_output) {
16921688
}
16931689
}
16941690
}
1695-
return;
16961691
}
16971692

16981693
// provided as a convenience function so that 3rd party utilities can know
16991694
// beforehand
17001695
void APar_ExtractBrands(char *filepath) {
17011696
FILE *a_file = APar_OpenISOBaseMediaFile(filepath, true);
1702-
char *buffer = (char *)calloc(1, sizeof(char) * 16);
1697+
char buffer[16] = {};
17031698
uint32_t atom_length = 0;
17041699
uint8_t file_type_offset = 0;
17051700
uint32_t compatible_brand = 0;
@@ -1779,8 +1774,4 @@ void APar_ExtractBrands(char *filepath) {
17791774
fprintf(stdout,
17801775
" ISO-copyright notices @ movie and/or track level "
17811776
"allowed.\n uuid private user extension tags allowed.\n");
1782-
1783-
free(buffer);
1784-
buffer = NULL;
1785-
return;
17861777
}

0 commit comments

Comments
 (0)