The assignment could be written shorter as: `SETPTR(uri, g_path_get_dirname(uri));` but this is rather a matter of taste.
I tested the changes and it "probably" works. I cannot test for sure as my `/` (root) is not writable for my user and this is good. This is probably also why nobody noticed earlier, I guess the root directory isn't writable for most users, maybe except on Windows and macOS.
@ChrisJAllan just for my curiosity, are you on Linux and your `/` is user writable?