X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/c0aa8967c26a4c261588e80cd06eefa80ee1b8d6..0e443c99edd2dd3bed4d916f1209e71c1629f2e1:/mac/macstore.c diff --git a/mac/macstore.c b/mac/macstore.c index 74fa8d97..35f31bdb 100644 --- a/mac/macstore.c +++ b/mac/macstore.c @@ -506,10 +506,10 @@ void *enum_settings_start(void) { OSErr error; struct enum_settings_state *state; - state = safemalloc(sizeof(*state)); + state = snew(struct enum_settings_state); error = get_session_dir(kDontCreateFolder, &state->vRefNum, &state->dirID); if (error != noErr) { - safefree(state); + sfree(state); return NULL; } state->index = 1; @@ -683,6 +683,7 @@ void store_host_key(const char *hostname, int port, char *resname; Str255 presname; Handle resvalue; + Handle reshandle; int id; /* Open the host key file */ @@ -708,7 +709,12 @@ void store_host_key(const char *hostname, int port, UseResFile(keyrefnum); resname = dupprintf("%s@%d:%s", keytype, port, hostname); c2pstrcpy(presname, resname); - + + reshandle = Get1NamedResource(FOUR_CHAR_CODE('TEXT'), presname); + if (reshandle != NULL) { + /* The resource exists, we're replacing a host key */ + RemoveResource(reshandle); + } error = PtrToHand(key, &resvalue, strlen(key)); if (error != noErr) goto out;