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 */
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.
*/
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.
while ( (line = fgetline(rfp)) ) {
if (strncmp(line, newtext, headerlen))
fputs(line, wfp);
+ sfree(line);
}
fclose(rfp);
}