X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/ae62eaeb01088430162fa96e8cca35f721ff376d..a607fe54c9f20934b57e29e9040b9dd0a4decf3a:/unix/uxstore.c diff --git a/unix/uxstore.c b/unix/uxstore.c index d9f60133..c5e40d46 100644 --- a/unix/uxstore.c +++ b/unix/uxstore.c @@ -299,8 +299,10 @@ void *open_settings_r(const char *sessionname) char *value = strchr(line, '='); struct skeyval *kv; - if (!value) + if (!value) { + sfree(line); continue; + } *value++ = '\0'; value[strcspn(value, "\r\n")] = '\0'; /* trim trailing NL */ @@ -395,16 +397,15 @@ FontSpec *read_setting_fontspec(void *handle, const char *name) return NULL; } } -int read_setting_filename(void *handle, const char *name, Filename *result) +Filename *read_setting_filename(void *handle, const char *name) { char *tmp = read_setting_s(handle, name); if (tmp) { - strncpy(result->path, tmp, sizeof(result->path)-1); - result->path[sizeof(result->path)-1] = '\0'; + Filename *ret = filename_from_str(tmp); sfree(tmp); - return TRUE; + return ret; } else - return FALSE; + return NULL; } void write_setting_fontspec(void *handle, const char *name, FontSpec *fs) @@ -418,9 +419,9 @@ void write_setting_fontspec(void *handle, const char *name, FontSpec *fs) write_setting_s(handle, suffname, fs->name); sfree(suffname); } -void write_setting_filename(void *handle, const char *name, Filename result) +void write_setting_filename(void *handle, const char *name, Filename *result) { - write_setting_s(handle, name, result.path); + write_setting_s(handle, name, result->path); } void close_settings_r(void *handle) @@ -590,9 +591,6 @@ void store_host_key(const char *hostname, int port, int headerlen; char *filename, *tmpfilename; - newtext = dupprintf("%s@%d:%s %s\n", keytype, port, hostname, key); - headerlen = 1 + strcspn(newtext, " "); /* count the space too */ - /* * Open both the old file and a new file. */ @@ -614,6 +612,9 @@ void store_host_key(const char *hostname, int port, filename = make_filename(INDEX_HOSTKEYS, NULL); rfp = fopen(filename, "r"); + newtext = dupprintf("%s@%d:%s %s\n", keytype, port, hostname, key); + headerlen = 1 + strcspn(newtext, " "); /* count the space too */ + /* * Copy all lines from the old file to the new one that _don't_ * involve the same host key identifier as the one we're adding. @@ -622,6 +623,7 @@ void store_host_key(const char *hostname, int port, while ( (line = fgetline(rfp)) ) { if (strncmp(line, newtext, headerlen)) fputs(line, wfp); + sfree(line); } fclose(rfp); }