Fix memory allocation on some queries
This commit is contained in:
parent
359f9b3a2d
commit
ee0315e620
|
|
@ -165,13 +165,9 @@ int mainloop(Parameters* p)
|
|||
while (go == true)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
getSim(simdata, simmap, &p->simon, &p->sim);
|
||||
|
||||
|
||||
if (p->simon == true)
|
||||
if (p->simon == true && simdata->simstatus > 1)
|
||||
{
|
||||
p->program_state = 1;
|
||||
if (p->cli == true)
|
||||
|
|
|
|||
|
|
@ -160,7 +160,6 @@ int getlaps(struct _h_connection* conn, const char* sessionname, LapDbo* laps, i
|
|||
int gettrack(struct _h_connection* conn, const char* trackname)
|
||||
{
|
||||
|
||||
|
||||
json_t* j_result;
|
||||
char* where_clause = h_build_where_clause(conn, "config_name=%s AND track_name=%s", "default", trackname);
|
||||
json_t* j_query = json_pack("{sss[s]s{s{ssss}}}", "table", "track_config", "columns", "track_config_id", "where", " ", "operator", "raw",
|
||||
|
|
@ -170,8 +169,8 @@ int gettrack(struct _h_connection* conn, const char* trackname)
|
|||
int res = h_select(conn, j_query, &j_result, &qq);
|
||||
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
//json_decref(j_query);
|
||||
//h_free(where_clause);
|
||||
int track_config = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK)
|
||||
|
|
@ -215,8 +214,6 @@ int getdriver(struct _h_connection* conn, const char* driver_name)
|
|||
int res = h_select(conn, j_query, &j_result, &qq);
|
||||
//slogi("here your query: %s", qq);
|
||||
// Deallocate j_query since it won't be needed anymore
|
||||
json_decref(j_query);
|
||||
h_free(where_clause);
|
||||
int driver_id = -1;
|
||||
// Test query execution result
|
||||
if (res == H_OK)
|
||||
|
|
@ -459,7 +456,7 @@ int addstint(struct _h_connection* conn, int sessionid, int driverid, int carid,
|
|||
json_object_set_new(values, "game_car_id", json_integer(carid));
|
||||
json_object_set_new(values, "laps", json_integer(0));
|
||||
json_object_set_new(values, "valid_laps", json_integer(0));
|
||||
json_object_set_new(values, "tyre", json_string("Vintage") );
|
||||
json_object_set_new(values, "tyre", json_string(simdata->tyrecompound) );
|
||||
// best_lap_id
|
||||
json_object_set_new(values, "is_finished", json_integer(0));
|
||||
|
||||
|
|
@ -484,6 +481,7 @@ int addstint(struct _h_connection* conn, int sessionid, int driverid, int carid,
|
|||
int addstintlap(struct _h_connection* conn, int stintid, SimData* simdata)
|
||||
{
|
||||
|
||||
slogt("adding stint lap");
|
||||
// stint laps
|
||||
// stint_lap_id | stint_id | sector_1 | sector_2 | sector_3 | grip | tyre | time | cuts | crashes
|
||||
// max_speed | avg_speed | finished_at
|
||||
|
|
@ -496,7 +494,8 @@ int addstintlap(struct _h_connection* conn, int stintid, SimData* simdata)
|
|||
json_t* values = json_object();
|
||||
|
||||
json_object_set_new(values, "stint_id", json_integer(stintid));
|
||||
json_object_set_new(values, "tyre", json_string("Vintage") );
|
||||
json_object_set_new(values, "tyre", json_string(simdata->tyrecompound) );
|
||||
json_array_append(json_arr, values);
|
||||
|
||||
char* qq;
|
||||
int res = h_insert(conn, root, &qq);
|
||||
|
|
@ -553,6 +552,8 @@ int addcar(struct _h_connection* conn, int carid, const char* carname)
|
|||
int addtelemetry(struct _h_connection* conn, int points, int stintid)
|
||||
{
|
||||
|
||||
slogt("adding telemetry record");
|
||||
|
||||
json_t* root = json_object();
|
||||
json_t* json_arr = json_array();
|
||||
|
||||
|
|
@ -589,7 +590,7 @@ int closelap(struct _h_connection* conn, int lapid, int sector1, int sector2, in
|
|||
|
||||
slogt("closing previous lap ", lapid);
|
||||
|
||||
char* query = malloc((sizeof(char)*632));
|
||||
char* query = malloc((sizeof(char)*650));
|
||||
sprintf(query, "UPDATE %s SET %s=%i, %s=%i, %s=%i, %s=%i, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, %s=%f, finished_at=NOW() WHERE lap_id=%i;",
|
||||
"laps", "time", simdata->lastlap, "sector_1", sector1, "sector_2", sector2, "sector_3", sector3,
|
||||
"right_front_tyre_temp", simdata->tyretemp[1],
|
||||
|
|
|
|||
Loading…
Reference in New Issue