@@ -45,49 +45,47 @@ int open(char* path,struct package* pkg)
45
45
}
46
46
47
47
void * parsers [][3 ] = {
48
- {parseinfo ,pkg ,NULL },
48
+ {parseinfo ,& pkg ,NULL },
49
49
50
- {parseraw ,& pkg -> info .make ,NULL },
51
50
{parseraw ,& pkg -> info .install ,NULL },
52
- {parseraw ,& pkg -> info .download ,NULL },
53
51
{parseraw ,& pkg -> info .prepare ,NULL },
54
52
{parseraw ,& pkg -> info .special ,NULL },
55
53
56
54
{parsenl ,& pkg -> files ,& pkg -> filesCount },
57
55
{parsenl ,& pkg -> dependencies ,& pkg -> dependenciesCount },
58
56
{parsenl ,& pkg -> optional ,& pkg -> optionalCount },
59
- { parsenl , & pkg -> inputs , & pkg -> inputsCount },
57
+
60
58
{parsenl ,& pkg -> locations ,& pkg -> locationsCount },
61
- {parseraw ,& pkg -> info . description ,NULL },
62
- {parsenl ,& pkg -> exports ,& pkg -> exportsCount }
59
+ {parseraw ,& pkg -> description ,NULL },
60
+ {parsenl ,& pkg -> config ,& pkg -> configCount }
63
61
};
64
62
65
63
void * pairs [][2 ] = {
66
64
{"info" ,parsers [0 ]},
67
65
68
- {"make" ,parsers [1 ]},
69
- {"install" ,parsers [2 ]},
70
- {"download" ,parsers [3 ]},
71
- {"prepare" ,parsers [4 ]},
72
- {"special" ,parsers [5 ]},
73
-
74
- {"files" ,parsers [6 ]},
75
- {"dependencies" ,parsers [7 ]},
76
- {"optional" ,parsers [8 ]},
77
- {"inputs" ,parsers [9 ]},
78
- {"locations" ,parsers [10 ]},
79
- {"description" ,parsers [11 ]},
80
- {"exports" ,parsers [12 ]},
66
+ {"install" ,parsers [1 ]},
67
+ {"prepare" ,parsers [2 ]},
68
+ {"special" ,parsers [3 ]},
69
+
70
+ {"files" ,parsers [4 ]},
71
+ {"dependencies" ,parsers [5 ]},
72
+ {"optional" ,parsers [6 ]},
73
+
74
+ {"locations" ,parsers [7 ]},
75
+ {"description" ,parsers [8 ]},
76
+ {"config" ,parsers [9 ]},
81
77
{NULL ,NULL }
82
78
};
83
79
84
80
void * infodict [][2 ] = {
81
+ // This is very stupid, but basically I assume that the name was obtained from the database
82
+ // This is to go around a memory leak caused by overwriting name when opening a package
83
+ // This is very stupid
85
84
{"name" ,& pkg -> name },
86
85
{"version" ,& pkg -> version },
87
86
{"type" ,& pkg -> type },
88
87
{"url" ,& pkg -> url },
89
88
{"license" ,& pkg -> license },
90
- {"sha256" ,& pkg -> sha256 },
91
89
{"environment" ,& pkg -> environment },
92
90
{NULL ,NULL }
93
91
};
@@ -104,7 +102,7 @@ int open(char* path,struct package* pkg)
104
102
for (unsigned int i = 0 ; i < count ; i ++ ) {
105
103
void * * options = hm_get (hm ,sections [i ]-> name );
106
104
if (options == NULL ) {
107
- msg (WARNING ,"Unknown section : %s" ,sections [i ]-> name );
105
+ msg (FATAL ,"Unknown section : %s" ,sections [i ]-> name );
108
106
free (sections [i ]-> buff );
109
107
continue ;
110
108
}
@@ -118,14 +116,15 @@ int open(char* path,struct package* pkg)
118
116
119
117
}
120
118
else {
121
- msg (WARNING ,"Unknown parser for section : %s" ,sections [i ]-> name );
119
+ msg (FATAL ,"Unknown parser for section : %s" ,sections [i ]-> name );
122
120
}
123
121
}
124
122
dbg (2 ,"done parsing | returning" );
125
123
126
124
// free sections
127
125
for (unsigned int i = 0 ; i < count ; i ++ ) {
128
126
free (sections [i ]-> name );
127
+ free (sections [i ]-> buff );
129
128
free (sections [i ]);
130
129
}
131
130
free (sections );
@@ -141,10 +140,10 @@ int open(char* path,struct package* pkg)
141
140
142
141
unsigned int parsenl (char * s ,char * * * dest )
143
142
{
144
- char * str ;
143
+ // char* str;
145
144
// the parseraw below is useless but i'll keep since in case
146
- parseraw (s ,& str );
147
- return splita (str ,'\n' ,dest );
145
+ // parseraw(s,&str);
146
+ return splita (s ,'\n' ,dest );
148
147
}
149
148
unsigned int parseraw (char * s , char * * dest )
150
149
{
@@ -153,7 +152,7 @@ unsigned int parseraw(char* s, char** dest)
153
152
// So we are just going to copy the pointer to it
154
153
// In the last version , we were copying the string to a new buffer
155
154
// Because the `s` string was a buffer that was going to be freed by `getline()`
156
- * dest = s ;
155
+ * dest = strdup ( s ) ;
157
156
return strlen (s );
158
157
}
159
158
@@ -180,29 +179,37 @@ unsigned int parseinfo(char *s, struct package* dest) {
180
179
char * key = strtok (nlist [i ], "=" );
181
180
char * value = strtok (NULL , "=" );
182
181
if (key == NULL || value == NULL ) {
183
- msg (WARNING , "Invalid key-value pair: '%s'" , nlist [i ]);
182
+ msg (FATAL , "Invalid key-value pair: '%s'" , nlist [i ]);
184
183
continue ;
185
184
}
186
185
187
186
// add to corresponding value in dict
188
187
char * * destbuff = hm_get (infohm , key );
188
+
189
+ if (strcmp (key , "name" ) == 0 )
190
+ {
191
+ // This is very stupid
192
+ free (nlist [i ]);
193
+ continue ;
194
+ }
189
195
if (destbuff == NULL ) {
190
- msg (WARNING , "Unknown key : '%s'" , key );
196
+ msg (FATAL , "Unknown key : '%s'" , key );
191
197
continue ;
192
198
}
193
199
194
200
* destbuff = strdup (value );
195
201
if (* destbuff == NULL ) {
196
202
msg (ERROR , "Error allocating memory for %s value" , key );
197
203
free (nlist );
198
- free (s );
204
+ // free(s);
199
205
return 0 ;
200
206
}
201
207
dbg (3 , "Setting destbuff to %p - %s" , * destbuff , * destbuff );
208
+ free (nlist [i ]);
202
209
}
203
210
204
211
free (nlist );
205
- free (s );
212
+ // free(s);
206
213
return 0 ;
207
214
}
208
215
@@ -221,7 +228,8 @@ unsigned int getsections(char* path,section*** sections) {
221
228
(void )current ;
222
229
unsigned int alloc = 0 ;
223
230
224
- while ((read = getline (& line ,& len ,fp )) != EOF ) {
231
+ while ((read = getline (& line ,& len ,fp )) != EOF )
232
+ {
225
233
if (line [0 ] == '#' || line [0 ] == '\n' || strlen (line ) < 2 ) {
226
234
continue ;
227
235
}
@@ -246,6 +254,7 @@ unsigned int getsections(char* path,section*** sections) {
246
254
}
247
255
strcat ((* sections )[sectionscount - 1 ]-> buff ,line );
248
256
}
257
+ free (line );
249
258
return sectionscount ;
250
259
}
251
260
@@ -259,15 +268,13 @@ int create(const char* path,struct package* pkg)
259
268
// i love hashmaps but here we'll use maparray
260
269
// we have the list[0] = section and list[1] = function to do stuff
261
270
void * list [][3 ] = {
262
- {"download" ,pkg -> info .download ,NULL },
263
271
{"prepare" ,pkg -> info .prepare ,NULL },
264
- {"make" ,pkg -> info .make ,NULL },
265
272
{"install" ,pkg -> info .install ,NULL },
266
273
{"special" ,pkg -> info .special ,NULL },
267
274
268
275
{"dependencies" ,pkg -> dependencies ,& pkg -> dependenciesCount },
269
276
{"optional" ,pkg -> optional ,& pkg -> optionalCount },
270
- {"description" ,pkg -> info . description ,NULL },
277
+ {"description" ,pkg -> description ,NULL },
271
278
272
279
{"locations" ,pkg -> locations ,& pkg -> locationsCount },
273
280
};
@@ -287,7 +294,6 @@ int create(const char* path,struct package* pkg)
287
294
if (pkg -> type != NULL ) fprintf (ecmp ,"type = %s\n" ,pkg -> type );
288
295
if (pkg -> license != NULL ) fprintf (ecmp ,"license = %s\n" ,pkg -> license );
289
296
if (pkg -> url != NULL ) fprintf (ecmp ,"url = %s\n" ,pkg -> url );
290
- if (pkg -> sha256 != NULL ) fprintf (ecmp ,"sha256 = %s\n" ,pkg -> sha256 );
291
297
fprintf (ecmp ,"\n" ); // for improved readability
292
298
293
299
for (unsigned int i = 0 ;i < sizeof (list ) / sizeof (list [0 ]);i ++ )
0 commit comments