Fix some bugs in projects ##projects

* Use r_file_is_directory
* Return true instead of false in r_project_rename
* Free core->prj->path before resetting it
* Check for null in r_project_rename
This commit is contained in:
RHL120 2022-12-06 19:08:23 +01:00 committed by GitHub
parent 4bef862bd2
commit ac513ddc34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View File

@ -15,16 +15,22 @@ R_API bool r_project_rename(RProject *p, const char *newname) {
return false;
}
char *newprjdir = r_file_new (p->path, "..", newname, NULL);
if (r_file_exists (newprjdir)) {
if (r_file_is_directory (newprjdir)) {
R_LOG_ERROR ("Cannot rename project");
free (newprjdir);
return false;
}
r_file_move (p->path, newprjdir);
free (p->path);
p->path = newprjdir;
free (p->name);
p->name = strdup (newname);
if (r_file_move (p->path, newprjdir)) {
char *new_name = strdup (newname);
if (new_name) {
free (p->path);
free (p->name);
p->path = newprjdir;
p->name = new_name;
return true;
}
}
free (newprjdir);
return false;
}

View File

@ -737,7 +737,8 @@ R_API bool r_core_project_save(RCore *core, const char *prj_name) {
free (cwd);
}
// LEAK : not always in heap free (prj_name);
free (prj_dir);
free (core->prj->path);
core->prj->path = prj_dir;
if (scr_null) {
r_config_set_b (core->config, "scr.null", true);
}

@ -0,0 +1 @@
Subproject commit a3ea888e318b8b841de6333e0663d649db2f8d36