forked from lda/telodendria
Fix a mutex bug in Db and some memory errors in Json
This commit is contained in:
parent
d26fad4619
commit
2e6c129263
2 changed files with 16 additions and 4 deletions
4
src/Db.c
4
src/Db.c
|
@ -353,7 +353,6 @@ DbLock(Db * db, char *prefix, char *key)
|
|||
}
|
||||
|
||||
ref->json = JsonDecode(fp);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if (!ref->json)
|
||||
|
@ -383,10 +382,11 @@ DbLock(Db * db, char *prefix, char *key)
|
|||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&db->lock);
|
||||
pthread_mutex_lock(&ref->lock);
|
||||
|
||||
finish:
|
||||
pthread_mutex_unlock(&db->lock);
|
||||
|
||||
Free(file);
|
||||
Free(hash);
|
||||
return ref;
|
||||
|
|
16
src/Json.c
16
src/Json.c
|
@ -707,6 +707,7 @@ JsonTokenSeek(JsonParserState * state)
|
|||
return;
|
||||
}
|
||||
state->tokenType = TOKEN_STRING;
|
||||
state->tokenLen = strlen(state->token);
|
||||
break;
|
||||
default:
|
||||
if (c == '-' || isdigit(c))
|
||||
|
@ -921,7 +922,7 @@ JsonDecodeObject(JsonParserState * state)
|
|||
JsonTokenSeek(state);
|
||||
if (JsonExpect(state, TOKEN_STRING))
|
||||
{
|
||||
char *key = Malloc(state->tokenLen);
|
||||
char *key = Malloc(state->tokenLen + 1);
|
||||
JsonValue *value;
|
||||
|
||||
if (!key)
|
||||
|
@ -933,6 +934,7 @@ JsonDecodeObject(JsonParserState * state)
|
|||
JsonTokenSeek(state);
|
||||
if (!JsonExpect(state, TOKEN_COLON))
|
||||
{
|
||||
Free(key);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -941,6 +943,7 @@ JsonDecodeObject(JsonParserState * state)
|
|||
|
||||
if (!value)
|
||||
{
|
||||
Free(key);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -1028,6 +1031,8 @@ error:
|
|||
HashMap *
|
||||
JsonDecode(FILE * stream)
|
||||
{
|
||||
HashMap *result;
|
||||
|
||||
JsonParserState state;
|
||||
|
||||
state.stream = stream;
|
||||
|
@ -1039,5 +1044,12 @@ JsonDecode(FILE * stream)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return JsonDecodeObject(&state);
|
||||
result = JsonDecodeObject(&state);
|
||||
|
||||
if (state.token)
|
||||
{
|
||||
Free(state.token);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue