summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2014-11-18 18:06:22 +0100
committerPali Rohár <pali.rohar@gmail.com>2014-11-18 18:06:22 +0100
commitf3d203c205c9d4f1192f7e989eeeb80187c230fc (patch)
treebd5da34fadeeff6a4a68cf5161c5cb5657a05034 /src/main.c
parent79a171e823872747cfe6a19f2af4d61b424eaa62 (diff)
download0xFFFF-f3d203c205c9d4f1192f7e989eeeb80187c230fc.tar.bz2
main: Correctly set and free processed images
This will fix more memory corruptions (specially at quit).
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index ff99dc3..34ebffd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -663,6 +663,9 @@ int main(int argc, char **argv) {
goto clean;
}
filter_images_by_type(type, &image_first);
+ /* make sure that fiasco_in has valid images */
+ if ( fiasco_in )
+ fiasco_in->first = image_first;
}
/* filter images by device */
@@ -674,11 +677,18 @@ int main(int argc, char **argv) {
goto clean;
}
filter_images_by_device(device, &image_first);
+ /* make sure that fiasco_in has valid images */
+ if ( fiasco_in )
+ fiasco_in->first = image_first;
}
/* filter images by hwrev */
- if ( filter_hwrev )
+ if ( filter_hwrev ) {
filter_images_by_hwrev(atoi(filter_hwrev_arg), &image_first);
+ /* make sure that fiasco_in has valid images */
+ if ( fiasco_in )
+ fiasco_in->first = image_first;
+ }
/* reorder images for flashing (first x-loader, second secondary) */
/* set 2nd and secondary images for cold-flashing */
@@ -742,11 +752,12 @@ int main(int argc, char **argv) {
image_ptr = next;
}
+ /* make sure that fiasco_in has valid images */
+ if ( fiasco_in )
+ fiasco_in->first = image_first;
+
}
- /* make sure that fiasco_in has valid images*/
- if ( fiasco_in )
- fiasco_in->first = image_first;
/* identify images */
if ( image_ident ) {
@@ -784,8 +795,9 @@ int main(int argc, char **argv) {
WARNING("Removing unknown image (specified by %s %s)", image_ptr->image->orig_filename ? "file" : "fiasco", image_ptr->image->orig_filename ? image_ptr->image->orig_filename : "image");
if ( image_ptr == image_first )
image_first = next;
- image_list_unlink(image_ptr);
- free(image_ptr);
+ if ( fiasco_in && image_ptr == fiasco_in->first )
+ fiasco_in->first = fiasco_in->first->next;
+ image_list_del(image_ptr);
}
image_ptr = next;
}
@@ -985,6 +997,8 @@ int main(int argc, char **argv) {
filter_images_by_device(dev->detected_device, &image_first);
if ( detected_hwrev )
filter_images_by_hwrev(dev->detected_hwrev, &image_first);
+ if ( fiasco_in && ( detected_device || detected_hwrev ) )
+ fiasco_in->first = image_first;
/* set kernel and initfs images for loading */
if ( dev_load ) {
@@ -1049,8 +1063,7 @@ int main(int argc, char **argv) {
if ( fiasco_in && image_kernel == fiasco_in->first )
fiasco_in->first = fiasco_in->first->next;
- image_list_unlink(image_kernel);
- free(image_kernel);
+ image_list_del(image_kernel);
image_kernel = NULL;
}
@@ -1061,11 +1074,10 @@ int main(int argc, char **argv) {
if ( image_initfs == image_first )
image_first = image_first->next;
- if ( fiasco_in && image_kernel == fiasco_in->first )
+ if ( fiasco_in && image_initfs == fiasco_in->first )
fiasco_in->first = fiasco_in->first->next;
- image_list_unlink(image_initfs);
- free(image_initfs);
+ image_list_del(image_initfs);
image_initfs = NULL;
}
}
@@ -1081,11 +1093,10 @@ int main(int argc, char **argv) {
if ( image_ptr == image_first )
image_first = image_first->next;
- if ( fiasco_in && image_kernel == fiasco_in->first )
+ if ( fiasco_in && image_ptr == fiasco_in->first )
fiasco_in->first = fiasco_in->first->next;
- image_list_unlink(image_ptr);
- free(image_ptr);
+ image_list_del(image_ptr);
image_ptr = next;
}
}