OSDN Git Service

fix postresdata_t owner and lifetime.
authorornse01 <ornse01@users.sourceforge.jp>
Sun, 15 May 2011 07:37:17 +0000 (07:37 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sun, 15 May 2011 07:37:17 +0000 (07:37 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchan/trunk@275 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/main.c
src/poptray.c
src/poptray.h

index 45ab44b..67c196d 100644 (file)
@@ -967,9 +967,8 @@ LOCAL VOID bchan_paste(bchan_t *bchan)
 {
        W err;
        PNT p;
-       postresdata_t *post = NULL;
 
-       err = poptray_gettraydata(&post);
+       err = poptray_gettraydata(bchan->resdata);
        if (err < 0) {
                datwindow_responsepasterequest(bchan->window, /* NACK */ 1, NULL);
                return;
@@ -979,12 +978,8 @@ LOCAL VOID bchan_paste(bchan_t *bchan)
        p.y = 0x8000;
        datwindow_responsepasterequest(bchan->window, /* ACK */ 0, &p);
 
-       if (post != NULL) {
-               if (bchan->resdata != NULL) {
-                       postresdata_delete(bchan->resdata);
-               }
-               bchan->resdata = post;
-               cfrmwindow_setpostresdata(bchan->confirm, post);
+       if (err > 0) {
+               cfrmwindow_setpostresdata(bchan->confirm, bchan->resdata);
                bchan->request_confirm_open = True;
        }
 }
@@ -1082,6 +1077,7 @@ LOCAL W bchan_initialize(bchan_t *bchan, VID vid, WID wid/*tmp*/, W exectype, da
        datrender_t *render;
        dattraydata_t *traydata;
        datretriever_t *retriever;
+       postresdata_t *resdata;
        ressubmit_t *submit;
        cookiedb_t *cookiedb;
        RECT w_work;
@@ -1125,6 +1121,11 @@ LOCAL W bchan_initialize(bchan_t *bchan, VID vid, WID wid/*tmp*/, W exectype, da
                DP_ER("datretriever_new error", 0);
                goto error_retriever;
        }
+       resdata = postresdata_new();
+       if (resdata == NULL) {
+               DP_ER("postresdata_new error", 0);
+               goto error_resdata;
+       }
        submit = ressubmit_new(cache);
        if (submit == NULL) {
                DP_ER("ressubmit_new error", 0);
@@ -1179,7 +1180,7 @@ LOCAL W bchan_initialize(bchan_t *bchan, VID vid, WID wid/*tmp*/, W exectype, da
        bchan->retriever = retriever;
        bchan->submit = submit;
        bchan->confirm = cfrmwindow;
-       bchan->resdata = NULL;
+       bchan->resdata = resdata;
        bchan->ngword = ngwordwindow;
        bchan->cookiedb = cookiedb;
 
@@ -1194,6 +1195,8 @@ error_mainmenu_initialize:
 error_cookiedb:
        ressubmit_delete(submit);
 error_submit:
+       postresdata_delete(resdata);
+error_resdata:
        datretriever_delete(retriever);
 error_retriever:
        dattraydata_delete(traydata);
index 2912162..886c4a7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * poptray.c
  *
- * Copyright (c) 2009 project bchan
+ * Copyright (c) 2009-2011 project bchan
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any damages
 # define DP_ER(msg, err) /**/
 #endif
 
-EXPORT W poptray_gettraydata(postresdata_t **post)
+EXPORT W poptray_gettraydata(postresdata_t *post)
 {
        TRAYREC *data;
        TR_VOBJREC *vobjrec = NULL;
-       postresdata_t *ret;
-       W i, size, recs, err;
+       W i, size, recs, err, ret = 0;
 
        err = tget_dat(NULL, 0, &size, -1);
        if (err < 0) {
@@ -79,17 +78,12 @@ EXPORT W poptray_gettraydata(postresdata_t **post)
        }
 
        if (vobjrec != NULL) {
-               ret = postresdata_new();
-               if (ret == NULL) {
-                       free(data);
-                       return 0;
-               }
-               postresdata_readfile(ret, &(vobjrec->vlnk));
-               *post = ret;
+               postresdata_readfile(post, &(vobjrec->vlnk));
+               ret = 1;
        }
 
        tset_dat(NULL, 0);
        free(data);
 
-       return 0;
+       return ret;
 }
index b667b40..b428ff2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * poptray.h
  *
- * Copyright (c) 2009 project bchan
+ * Copyright (c) 2009-2011 project bchan
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any damages
@@ -30,6 +30,6 @@
 #ifndef __POPTRAY_H__
 #define __POPTRAY_H__
 
-IMPORT W poptray_gettraydata(postresdata_t **post);
+IMPORT W poptray_gettraydata(postresdata_t *post);
 
 #endif