X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgbytes.c;h=9d89139bcc646a217c5ab070365e695e880f232e;hb=ba446f6c333a4646f7cdbbba4855a7af512f0a6f;hp=266e257ae07701ec55044a565ea65f47c58d0146;hpb=f854d3849b889fb3447750e09a4982bccf2f6e3d;p=platform%2Fupstream%2Fglib.git diff --git a/glib/gbytes.c b/glib/gbytes.c index 266e257..9d89139 100644 --- a/glib/gbytes.c +++ b/glib/gbytes.c @@ -200,8 +200,15 @@ g_bytes_new_take_zero_copy_fd (gint fd) /* We already checked this is a memfd... */ g_assert_se (fstat (fd, &buf) == 0); + if (buf.st_size == 0) + { + g_assert_se (close (fd) == 0); + + return g_bytes_new (NULL, 0); + } + bytes = g_bytes_allocate (sizeof (GBytesData), fd, buf.st_size); - bytes->data = mmap (NULL, buf.st_size, PROT_READ, MAP_SHARED, fd, 0); + bytes->data = mmap (NULL, buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (bytes->data == MAP_FAILED) /* this is similar to malloc() failing, so do the same... */ g_error ("mmap() on memfd failed: %s\n", g_strerror (errno));