- jsonobj = (struct json *)palloc(sizeof(struct json));
-
+ //jsonobj = (struct json *)palloc(sizeof(struct json));
+ jsonobj = talloc(NULL, struct json);
+ if (!jsonobj)
+ errx(1, "talloc error");
+
- jsonobj->module = (char *)palloc(sizeof(char) * (modulename - 1));
- strncpy(jsonobj->module, infofile[0], modulename - 1);
- jsonobj->module[modulename - 1] = '\0';
+
+ jsonobj->module = talloc_strndup(jsonobj, infofile[0], modulename - 1);
+ if (!jsonobj->module)
+ errx(1, "talloc error");
+
+ //jsonobj->module = (char *)palloc(sizeof(char) * (modulename - 1));
+ //strncpy(jsonobj->module, infofile[0], modulename - 1);
+ //jsonobj->module[modulename - 1] = '\0';
- char **infofile = NULL;
- unsigned int count = 0, j = 0, size = 0;
+ char **infofile;
+ unsigned int count = 0, j = 0, num_lines = 0;
- while(file[size++]);
- infofile = (char **) palloc(size * sizeof(char *));
+ while (file[num_lines++]);
+ infofile = talloc_array(NULL, char *, num_lines);
+ //(char **) palloc(size * sizeof(char *));
else if (strstarts(file[j], " *"))
infofile[count++] = file[j] + 2;
else {
else if (strstarts(file[j], " *"))
infofile[count++] = file[j] + 2;
else {
fprintf(fp,"\"Module\":\"%s\",\n",jsonobj->module);
fprintf(fp,"\"Title\":\"%s\",\n",jsonobj->title);
fprintf(fp,"\"Author\":\"%s\",\n",jsonobj->author);
fprintf(fp,"\"Description\":[\n");
fprintf(fp,"\"Module\":\"%s\",\n",jsonobj->module);
fprintf(fp,"\"Title\":\"%s\",\n",jsonobj->title);
fprintf(fp,"\"Author\":\"%s\",\n",jsonobj->author);
fprintf(fp,"\"Description\":[\n");
- while(jsonobj->desc[j++])
- fprintf(fp,"{\n\"str\":\"%s\"\n},\n",jsonobj->desc[j - 1]);
+ for (j = 0; jsonobj->desc[j]; j++)
+ fprintf(fp,"{\n\"str\":\"%s\"\n},\n",jsonobj->desc[j]);
- cmd = aprintf("INSERT INTO search VALUES(\"%s\",\"%s\",\"%s\",'%s\');",
- jsonobj->module, jsonobj->author, jsonobj->title, strjoin(NULL,jsonobj->desc,"\n"));
+ cmd = talloc_asprintf(NULL, "INSERT INTO search VALUES(\"%s\",\"%s\",\"%s\",'%s\');",
+ jsonobj->module, jsonobj->author, jsonobj->title, desc);
- cmd = aprintf("UPDATE search set author=\"%s\", title=\"%s\", desc='%s\' where module=\"%s\";",
- jsonobj->author, jsonobj->title, strjoin(NULL,jsonobj->desc,"\n"), jsonobj->module);
-
+ cmd = talloc_asprintf(NULL, "UPDATE search set author=\"%s\", title=\"%s\", desc='%s\' where module=\"%s\";",
+ jsonobj->author, jsonobj->title, desc, jsonobj->module);
+
- struct json *jsonobj = NULL;
-
- if(argc < 4) {
- printf("usage: infotojson infofile jsonfile author sqlitedb\n");
+ talloc_enable_leak_report();
+ if (argc < 4) {
+ errx(1, "usage: infotojson infofile jsonfile author [sqlitedb]\n");