History

9pex: fixes for two (unlikely but) possible memory leaks

Sigrid Solveig Haflínudóttir committed 5 years ago

Commit d93d3851 parent e05b2fc1 file · +11 −8Browse files

Unified · Split

9pex.c+11−8
@@ -260,12 +260,16 @@ newfid(C9fid fid, char *path, char **err) · 259 unmodified lines
260 if (statpath(path, &st, err) != 0)260 if (statpath(path, &st, err) != 0)
261 return NULL;261 return NULL;
262 262
263 if ((f = calloc(1, sizeof(*f))) == NULL) {263 if ((f = calloc(1, sizeof(*f))) == NULL || (f->path = strdup(path)) == NULL) {
264nomem:
265 if (f != NULL) {
266 free(f->path);
267 free(f);
268 }
264 *err = Enomem;269 *err = Enomem;
265 return NULL;270 return NULL;
266 }271 }
267 f->fd = -1;272 f->fd = -1;
268 f->path = strdup(path);
269 f->name = strrchr(f->path, '/');273 f->name = strrchr(f->path, '/');
270 if (f->name == NULL)274 if (f->name == NULL)
271 f->name = f->path;275 f->name = f->path;
@@ -281,10 +285,8 @@ newfid(C9fid fid, char *path, char **err) · 9 unmodified lines
281 }285 }
282 }286 }
283 if (i >= numfids) {287 if (i >= numfids) {
284 if ((newfids = realloc(fids, (numfids+1)*sizeof(*fids))) == NULL) {288 if ((newfids = realloc(fids, (numfids+1)*sizeof(*fids))) == NULL)
285 *err = Enomem;289 goto nomem;
286 return NULL;
287 }
288 fids = newfids;290 fids = newfids;
289 fids[numfids++] = f;291 fids[numfids++] = f;
290 }292 }
@@ -393,9 +395,10 @@ walk(C9fid fid, C9fid nfid, char *el[], C9qid *qids[], char **err) · 102 unmodified lines
393 path[plen+1+ellen] = 0;395 path[plen+1+ellen] = 0;
394 396
395 if (!rootescape) {397 if (!rootescape) {
396 if ((real = realpath(path, NULL)) == NULL)398 real = realpath(path, NULL);
397 break;
398 free(path);399 free(path);
400 if (real == NULL)
401 break;
399 if (strlen(real) < rootlen) { /* don't escape root */402 if (strlen(real) < rootlen) { /* don't escape root */
400 free(real);403 free(real);
401 real = strdup(rootpath);404 real = strdup(rootpath);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t