I am having some issues with 2 main TBA functions ( i thnk this is just valgrind) but i figured i would ask. There is another that i may or may not get help with here.
valgrind --log-file="leak.txt" --leak-check=full --show-reachable=yes --track-origins=yes bin/circle_dev_w -q 6001
==848167== Memcheck, a memory error detector
==848167== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==848167== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==848167== Command: bin/circle_dev_w -q 6001
==848167== Parent PID: 840102
==848167==
==848167== Conditional jump or move depends on uninitialised value(s)
==848167== at 0x1B8B40: fread_string (db.c:3915)
==848167== by 0x1C4FBA: load_config (db.c:5862)
==848167== by 0x1268B2: main (comm.c:285)
==848167== Uninitialised value was created by a stack allocation
==848167== at 0x1B8B22: fread_string (db.c:3915)
Code:
char *fread_string(FILE *fl, const char *error)
{
char buf[MAX_STRING_LENGTH] = {'\0'}, tmp[513] = {'\0'};
char *point = NULL;
int done = 0, length = 0, templength = 0;
*buf = '\0';
*tmp = '\0';
do
{
memset(tmp, '\0', 513);
if (!fgets(tmp, 512, fl))
{
log("SYSERR: fread_string: format error at or near %s", error);
exit(1);
}
/* If there is a '~', end the string; else put an "\r\n" over the '\n'. */
/* now only removes trailing ~'s -- Welcor */
point = strchr(tmp, '\0');
if (point == NULL)
{
log("SYSERR: freed_string: end of string not found (db.c)");
log("String: %s", tmp);
exit(1);
}
[b] for (point--; (*point == '\r' || *point == '\n' || point == 0); point--) ============> 3915[/b]
;
if (*point == '~')
{
*point = '\0';
done = 1;
}
else
{
*(++point) = '\r';
*(++point) = '\n';
*(++point) = '\0';
}
==848167== Conditional jump or move depends on uninitialised value(s)
==848167== at 0x1BD9A0: fread_clean_string (db.c:3982)
==848167== by 0x21E8C6: read_ibt (ibt.c:197)
==848167== by 0x21F08A: load_ibt_file (ibt.c:279)
==848167== by 0x1C6C71: boot_db (db.c:1122)
==848167== by 0x126D48: init_game (comm.c:561)
==848167== by 0x126D48: main (comm.c:395)
==848167== Uninitialised value was created by a stack allocation
==848167== at 0x1BD981: fread_clean_string (db.c:3982)
/* fread_clean_string is the same as fread_string, but skips preceding spaces */
Code:
char *fread_clean_string(FILE *fl, const char *error)
{
char buf[MAX_STRING_LENGTH] = {'\0'}, tmp[513] = {'\0'};
char *point = NULL, c = '\0';
int done = 0, length = 0, templength = 0;
*buf = '\0';
*tmp = '\0';
do
{
if (feof(fl))
{
log("%s", "fread_clean_string: EOF encountered on read.");
return 0;
}
c = getc(fl);
} while (isspace(c));
ungetc(c, fl);
do
{
if (!fgets(tmp, 512, fl))
{
log("SYSERR: fread_clean_string: format error at or near %s", error);
exit(1);
}
/* If there is a '~', end the string; else put an "\r\n" over the '\n'. */
/* now only removes trailing ~'s -- Welcor */
point = strchr(tmp, '\0');
[b] [/b] for (point--; (*point == '\r' || *point == '\n'); point--) ==================>3982
;
if (*point == '~')
{
*point = '\0';
done = 1;
}
else
{
*(++point) = '\r';
*(++point) = '\n';
*(++point) = '\0';
}
==848167== HEAP SUMMARY:
==848167== in use at exit: 3,600,349 bytes in 2,677 blocks
==848167== total heap usage: 2,109,239 allocs, 2,106,562 frees, 272,968,248 bytes allocated
==848167==
==848167== 5 bytes in 1 blocks are still reachable in loss record 1 of 369
==848167== at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==848167== by 0x4BEC60E: strdup (strdup.c:42)
==848167== by 0x4AE7B56: ??? (in /usr/lib/x86_64-linux-gnu/libmariadb.so.3)
==848167== by 0x4AEC1DD: ??? (in /usr/lib/x86_64-linux-gnu/libmariadb.so.3)
==848167== by 0x4BDDF67: __pthread_once_slow (pthread_once.c:116)
==848167== by 0x249B69: connect_to_mysql (mysql.c:62)
==848167== by 0x1C68AB: boot_db (db.c:984)
==848167== by 0x126D48: init_game (comm.c:561)
==848167== by 0x126D48: main (comm.c:395)
Code:
void connect_to_mysql()
{
if (mysql_library_init(0, NULL, NULL)) =================> 62
{
log("SYSERR: Unable to initialize MySQL library.");
exit(1);
}
if (!(conn = mysql_init(NULL)))
{
log("SYSERR: Unable to initialize MySQL connection.");
exit(1);
}
my_bool reconnect = 1;
mysql_options(conn, MYSQL_OPT_RECONNECT, &reconnect);
if (!mysql_real_connect(conn, MYSQL_SERVER, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB, 0, NULL, 0)) ===========> 78 same as 62 debug
{
log("SYSERR: Unable to connect to MySQL: %s", mysql_error(conn));
exit(1);
}