[sysprof: 52/63] libsysprof-capture: wrap strdup to be NULL-safe
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof: 52/63] libsysprof-capture: wrap strdup to be NULL-safe
- Date: Sat, 4 Jul 2020 18:33:43 +0000 (UTC)
commit cef698e6585c0ea2d86dbee415836525b631185f
Author: Christian Hergert <chergert redhat com>
Date: Thu Jul 2 12:16:47 2020 -0700
libsysprof-capture: wrap strdup to be NULL-safe
src/libsysprof-capture/sysprof-capture-condition.c | 2 +-
src/libsysprof-capture/sysprof-capture-reader.c | 6 +++---
src/libsysprof-capture/sysprof-macros-internal.h | 2 ++
3 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-condition.c
b/src/libsysprof-capture/sysprof-capture-condition.c
index 5322e09..8f89157 100644
--- a/src/libsysprof-capture/sysprof-capture-condition.c
+++ b/src/libsysprof-capture/sysprof-capture-condition.c
@@ -519,7 +519,7 @@ sysprof_capture_condition_new_where_file (const char *path)
return NULL;
self->type = SYSPROF_CAPTURE_CONDITION_WHERE_FILE;
- self->u.where_file = strdup (path);
+ self->u.where_file = sysprof_strdup (path);
if (self->u.where_file == NULL)
{
free (self);
diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c
index cfa42a6..2b103b5 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.c
+++ b/src/libsysprof-capture/sysprof-capture-reader.c
@@ -284,7 +284,7 @@ sysprof_capture_reader_new (const char *filename,
return NULL;
}
- self->filename = strdup (filename);
+ self->filename = sysprof_strdup (filename);
return self;
}
@@ -1080,7 +1080,7 @@ sysprof_capture_reader_save_as (SysprofCaptureReader *self,
}
if (self->filename == NULL)
- self->filename = strdup (filename);
+ self->filename = sysprof_strdup (filename);
close (fd);
@@ -1173,7 +1173,7 @@ sysprof_capture_reader_copy (SysprofCaptureReader *self)
*copy = *self;
copy->ref_count = 1;
- copy->filename = strdup (self->filename);
+ copy->filename = sysprof_strdup (self->filename);
copy->fd = fd;
copy->end_time = self->end_time;
copy->st_buf = self->st_buf;
diff --git a/src/libsysprof-capture/sysprof-macros-internal.h
b/src/libsysprof-capture/sysprof-macros-internal.h
index 9fed465..cf814da 100644
--- a/src/libsysprof-capture/sysprof-macros-internal.h
+++ b/src/libsysprof-capture/sysprof-macros-internal.h
@@ -73,3 +73,5 @@
if (_p != NULL) \
(destroy) (_p); \
} while (0)
+
+#define sysprof_strdup(s) ((s) ? strdup(s) : NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]