Skip to content

Commit 68c8135

Browse files
committed
Free memory allocated by GetImagePath
Ensure the string returned by GetImagePath is properly freed to prevent memory leaks.
1 parent 50ea75d commit 68c8135

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/stub.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ int main(int argc, char *argv[])
2020
UnpackContext *unpack_ctx = NULL;
2121
OperationModes op_modes = 0;
2222
const char *extract_dir = NULL;
23+
char *image_path = NULL;
2324

2425
/*
2526
Initialize signal and control handling so the parent process remains
@@ -34,8 +35,8 @@ int main(int argc, char *argv[])
3435
}
3536

3637
/* Find name of image */
37-
char *image_path = GetImagePath();
38-
if (image_path == NULL) {
38+
image_path = GetImagePath();
39+
if (!image_path) {
3940
FATAL("Failed to get executable name");
4041
goto cleanup;
4142
}
@@ -116,6 +117,10 @@ int main(int argc, char *argv[])
116117
Cleanup failures are non-critical and logged as DEBUG only.
117118
*/
118119

120+
if (image_path) {
121+
free(image_path);
122+
}
123+
119124
if (unpack_ctx) {
120125
ClosePackFile(unpack_ctx);
121126
unpack_ctx = NULL;

0 commit comments

Comments
 (0)