Salut a tous!

J'ai cette fonction qui est appeler dans un loop dans le main.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
int  import_image(char *image_filename, char *make1, char *model1, char *year1)
{
	char *make;
	char *model;
	char *year;
	char *file = "car_id";
	char thumb[100];
	char id[50];
	char filex[15];
	int d;
 
	MYSQL mysql;
	MYSQL_RES *result;
	MYSQL_ROW row;
 
	unsigned int num_fields;
	unsigned int i;
	char query_def[1000];
 
	make = str_replace("\"", "", make1);
	model = str_replace("\"", "", model1);
	year = str_replace("\"", "", year1);
 
	//start mysql sequence to get the last id of the car inserted...
	if(mysql_init(&mysql)==NULL)
	{
		printf("\nFailed to initate MySQL connection");
		exit(1);
	}
	sprintf(query_def,"SELECT t1.car_id FROM tbl_cars AS t1 ORDER BY t1.car_id DESC LIMIT 1");
 
	//test local
	if (!mysql_real_connect(&mysql,"localhost","root","",NULL,0,NULL,0)) 
	{
	    printf( "Failed to connect to MySQL: Error: %s\n", mysql_error(&mysql));
	    exit(1);
	}
 
	if(mysql_select_db(&mysql,"test_import")==0)
 
	{
		if(mysql_exec_sql(&mysql,query_def)==0) <--- ligne qui segfault
		{
	/*		MYSQL_RES *result;
			result = mysql_use_result(&mysql);
 
			if (result)  // there are rows
			{
				// retrieve rows, then call mysql_free_result(result)
				MYSQL_ROW row;
				if((row = mysql_fetch_row(result)))
				{
					unsigned long *lengths = mysql_fetch_lengths(result);
					if(lengths[0] > 0)
 
					{
					  printf("%s", row[0]);
					  int i;
					  char ran[11];
					  i = rand();
					  sprintf(ran, "%d", i);
					  strcpy(id, row[0]);
					  d = strlen(id);
					  strcat(filex, file);
					  strcat(filex, id);
					  strcat(filex, "_");
					  strcat(filex, ran);
					  strcpy(thumb, filex);
					  strcat(filex, "_large.jpg");
					  strcat(thumb, ".jpg");
					  //all good? check the directory...
					  check_directory(image_filename, filex, thumb, make, model, year);
				   	 // exit(0);
					}
				}
				mysql_free_result(result);
			}*/
		}
		free(query_def);
	//	mysql_close(&mysql);
 
	}
 
	    //printf( "Database Selected\n");
	//else
	  //  printf( "Failed to connect to Database: Error: %s\n", mysql_error(&mysql));
 
	//mysql_close(&mysql);
 
}
Je me demande si c'est parce que je ne free pas query_def, mais meme avec un free, pareil...