Remove unneeded strdup(3)

pull/36/head
Baptiste Daroussin 2012-08-14 16:16:06 +02:00
parent 666019cfd0
commit 38abe86a17
1 changed files with 14 additions and 16 deletions

30
pkg.c
View File

@ -164,7 +164,7 @@ pkg_new_from_file(const char *filename, FILE *f)
while (pkg_fgetline(readbuf, PKG_BUFSIZE, f) != NULL) while (pkg_fgetline(readbuf, PKG_BUFSIZE, f) != NULL)
{ {
char op, *p, *key = NULL, *value = NULL; char op, *p, *key, *value;
readbuf[strlen(readbuf) - 1] = '\0'; readbuf[strlen(readbuf) - 1] = '\0';
@ -172,19 +172,24 @@ pkg_new_from_file(const char *filename, FILE *f)
while (*p && (isalpha(*p) || isdigit(*p) || *p == '_' || *p == '.')) while (*p && (isalpha(*p) || isdigit(*p) || *p == '_' || *p == '.'))
p++; p++;
key = strndup(readbuf, p - readbuf); key = readbuf;
if (!isalpha(*key) && !isdigit(*p)) if (!isalpha(*key) && !isdigit(*p))
goto cleanup; continue;
while (*p && isspace(*p)) {
/* set to null to avoid trailing spaces in key */
*p = '\0';
p++;
}
op = *p;
*p = '\0';
p++;
while (*p && isspace(*p)) while (*p && isspace(*p))
p++; p++;
op = *p++; value = p;
while (*p && isspace(*p))
p++;
value = strdup(p);
switch (op) switch (op)
{ {
@ -214,13 +219,6 @@ pkg_new_from_file(const char *filename, FILE *f)
default: default:
break; break;
} }
cleanup:
if (key)
free(key);
if (value)
free(value);
} }
fclose(f); fclose(f);