about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2022-08-02 14:20:34 +0200
committerGitHub <noreply@github.com>2022-08-02 14:20:34 +0200
commit9d094f73e39b18367fab814be26efabe3c468d28 (patch)
treee2e5d08606d7c7e1d6cbaa6a63efe69b274fa4f7
parent0e02cc3cf6fb2ff519b1e0a8bed613d906495af4 (diff)
parent932e7826aa4ffbfc587c1749c30979ce514477d4 (diff)
downloadprofani-tty-9d094f73e39b18367fab814be26efabe3c468d28.tar.gz
Merge pull request #1740 from profanity-im/fix/1738-avatar-seg
Check for error before trying to append it
-rw-r--r--src/common.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/common.c b/src/common.c
index 3a1b9cc4..b2496087 100644
--- a/src/common.c
+++ b/src/common.c
@@ -445,15 +445,16 @@ get_mentions(gboolean whole_word, gboolean case_sensitive, const char* const mes
 gboolean
 call_external(gchar** argv, gchar** std_out, gchar** std_err)
 {
+    GError *spawn_error, *status_error;
+    gboolean spawn_result;
+    gint exit_status;
+
     GSpawnFlags flags = G_SPAWN_SEARCH_PATH;
     if (std_out == NULL)
         flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
     if (std_err == NULL)
         flags |= G_SPAWN_STDERR_TO_DEV_NULL;
 
-    gint exit_status;
-    gboolean spawn_result;
-    GError* spawn_error;
     spawn_result = g_spawn_sync(NULL, // Inherit the parent PWD.
                                 argv,
                                 NULL, // Inherit the parent environment.
@@ -462,12 +463,19 @@ call_external(gchar** argv, gchar** std_out, gchar** std_err)
                                 std_out, std_err,
                                 &exit_status, &spawn_error);
 
-    if (!spawn_result
-        || !g_spawn_check_exit_status(exit_status, &spawn_error)) {
+    if (!spawn_result || !g_spawn_check_exit_status(exit_status, &status_error)) {
         gchar* cmd = g_strjoinv(" ", argv);
-        log_error("Spawning '%s' failed with '%s'.", cmd, spawn_error->message);
+        if (spawn_error && spawn_error->message) {
+            log_error("Spawning '%s' failed with '%s'.", cmd, spawn_error->message);
+            g_error_free(spawn_error);
+        } else if (status_error && status_error->message) {
+            log_error("Spawning '%s' failed with '%s'.", cmd, status_error->message);
+            g_error_free(status_error);
+            spawn_result = FALSE;
+        } else {
+            log_error("Spawning '%s' failed with.", cmd);
+        }
         g_free(cmd);
-        g_error_free(spawn_error);
     }
 
     return spawn_result;
a id='n204' href='#n204'>204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380