summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorRichard Wilson <rjw@netsurf-browser.org>2006-06-28 22:45:48 +0000
committerRichard Wilson <rjw@netsurf-browser.org>2006-06-28 22:45:48 +0000
commitc490c7f586ae7639dc7f4215544db4e98a7d26b8 (patch)
treeeb9fc82f45a1c1d44f7af445d266580e143cd6e5 /desktop
parent5378cd3330f4954b52ba70f4e57b88cf898a3100 (diff)
downloadnetsurf-c490c7f586ae7639dc7f4215544db4e98a7d26b8.tar.gz
netsurf-c490c7f586ae7639dc7f4215544db4e98a7d26b8.tar.bz2
Handle memory exhaustion better.
svn path=/trunk/netsurf/; revision=2666
Diffstat (limited to 'desktop')
-rw-r--r--desktop/history_core.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/desktop/history_core.c b/desktop/history_core.c
index edb3fd248..2a0b366ca 100644
--- a/desktop/history_core.c
+++ b/desktop/history_core.c
@@ -123,6 +123,7 @@ struct history *history_clone(struct history *history)
new_history->start = history_clone_entry(new_history,
new_history->start);
if (!history->start) {
+ LOG(("Insufficient memory to clone history"));
warn_user("NoMemory", 0);
history_destroy(new_history);
return 0;
@@ -151,10 +152,8 @@ struct history_entry *history_clone_entry(struct history *history,
/* clone the entry */
new_entry = malloc(sizeof *entry);
- if (!new_entry) {
- history_destroy(history);
+ if (!new_entry)
return 0;
- }
memcpy(new_entry, entry, sizeof *entry);
new_entry->url = strdup(entry->url);
if (entry->frag_id)
@@ -163,10 +162,10 @@ struct history_entry *history_clone_entry(struct history *history,
if (((entry->url) && (!new_entry->url)) ||
((entry->title) && (!new_entry->title)) ||
((entry->frag_id) && (!new_entry->frag_id))) {
- free(entry->url);
- free(entry->title);
- free(entry->frag_id);
- history_destroy(history);
+ free(new_entry->url);
+ free(new_entry->title);
+ free(new_entry->frag_id);
+ free(new_entry);
return 0;
}
@@ -177,8 +176,8 @@ struct history_entry *history_clone_entry(struct history *history,
/* recurse for all children */
for (child = new_entry->forward; child; child = child->next) {
new_child = history_clone_entry(history, child);
- assert(new_child);
- new_child->back = entry;
+ if (new_child)
+ new_child->back = entry;
if (prev)
prev->next = new_child;
if (new_entry->forward == child)
@@ -187,6 +186,8 @@ struct history_entry *history_clone_entry(struct history *history,
new_entry->forward_pref = new_child;
if (new_entry->forward_last == child)
new_entry->forward_last = new_child;
+ if (!new_child)
+ return 0;
prev = new_child;
}
return new_entry;