From: greatim Date: Wed, 7 Dec 2016 06:46:39 +0000 (+0900) Subject: fix potential bugs X-Git-Tag: accepted/tizen/3.0/common/20161207.195648^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F103063%2F1;p=sdk%2Ftarget%2Fsdbd.git fix potential bugs fix potential bugs 1. NO_LOCK.STAT for errno in log.h 2. NULL_AFTER_DEREF by asprintf Change-Id: I3470fd2d8d0b86c3417add3657a38b45d1222626 Signed-off-by: greatim --- diff --git a/src/log.h b/src/log.h index 3d55707..f237e15 100644 --- a/src/log.h +++ b/src/log.h @@ -73,27 +73,26 @@ void sdb_qemu_trace(const char* fmt, ...); # define D(...) \ do { \ if (SDB_TRACING) { \ - int save_errno = errno; \ sdb_mutex_lock(&D_lock); \ + int save_errno = errno; \ fprintf(stderr, "%s::%s():", \ __FILE__, __FUNCTION__); \ errno = save_errno; \ fprintf(stderr, __VA_ARGS__ ); \ fflush(stderr); \ - sdb_mutex_unlock(&D_lock); \ errno = save_errno; \ + sdb_mutex_unlock(&D_lock); \ } \ } while (0) # define DR(...) \ do { \ if (SDB_TRACING) { \ - int save_errno = errno; \ sdb_mutex_lock(&D_lock); \ - errno = save_errno; \ + int save_errno = errno; \ fprintf(stderr, __VA_ARGS__ ); \ fflush(stderr); \ - sdb_mutex_unlock(&D_lock); \ errno = save_errno; \ + sdb_mutex_unlock(&D_lock); \ } \ } while (0) #else diff --git a/src/services.c b/src/services.c index d2d1500..4395a1d 100644 --- a/src/services.c +++ b/src/services.c @@ -338,12 +338,13 @@ void inoti_service(int fd, void *arg) if (event->mask & IN_CREATE) { if (!(event->mask & IN_ISDIR)) { char *cspath = NULL; - int len = asprintf(&cspath, "%s/%s", CS_PATH, - event->name); - D( "The file %s was created.\n", cspath); - writex(fd, cspath, len); - if (cspath != NULL) { + int len = asprintf(&cspath, "%s/%s", CS_PATH, event->name); + if (len >= 0) { + D( "The file %s was created.\n", cspath); + writex(fd, cspath, len); free(cspath); + } else { + D( "asprintf was failed\n" ); } } }